Skip to content

Instantly share code, notes, and snippets.

@etipton
Last active January 7, 2016 12:47
Show Gist options
  • Save etipton/7a86a922feb9922b0cf8 to your computer and use it in GitHub Desktop.
Save etipton/7a86a922feb9922b0cf8 to your computer and use it in GitHub Desktop.
Ruby TCP server, port 2000
#!/usr/bin/env ruby
require 'socket'
server = TCPServer.new(2000)
loop do
sock = server.accept
# sleep 6 # if you want to test timeouts
# puts sock.recvmsg[0] # if you want to test receiving request data
# sock.sendmsg("monkey") # if you want to test sending response data
# if you want to simulate ECONNRESET
# linger = [1,0].pack('ii')
# sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, linger)
sock.close
end
@etipton
Copy link
Author

etipton commented Jan 7, 2016

written / tested using ruby 2.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment