One line Ruby webserver for testing timeout handling

I was just changing error handling around net timeouts, and naturally I wanted to test it. There are plenty of good tools floating around for throttling your network connection to test under different speeds and conditions, but frankly I couldn’t be bothered with all that.

The Ruby:

require 'socket'

t =

while s = t.accept
  puts 'accepted connection, snoozin :)'
  sleep 60

The bash:

ruby -rsocket -e "t =; while s = t.accept; puts 'accepted connection, snoozin :)'; sleep 60; s.close; end"
Respond to this post via e-mail