require 'socket' successes = 0 backoff = 0.5 loop do begin TCPSocket.open('127.0.0.1', 22000) do |sock| sock.send("sally #{rand(101)} #{rand(101)}\n", 0) sock.recv(100) sock.close STDOUT.write('.') STDOUT.flush end successes += 1 backoff = 0.5 sleep 0.01 rescue STDOUT.write('E') STDOUT.flush STDERR.write("\nmade it #{successes} times. sleeping #{backoff} secs\n") successes = 0 sleep backoff backoff *= 2 end end