Skip to content

Instantly share code, notes, and snippets.

@seanbollin
Last active December 28, 2015 07:39
Show Gist options
  • Save seanbollin/7465954 to your computer and use it in GitHub Desktop.
Save seanbollin/7465954 to your computer and use it in GitHub Desktop.
mucking around with a TCP server in Ruby
require 'socket'
clients = []
server = TCPServer.open(5555)
loop {
Thread.start(server.accept) do |client|
clients << client
p clients.length
loop {
received = client.recv(1024)
if received == ""
puts 'Client connection closed.'
client.close
end
puts '--'
puts received
# client.puts "A damp dark room."
# TODO: Break out of loop and shut-down thread
# rescue SystemCallError :e
}
# client.close
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment