Skip to content

Instantly share code, notes, and snippets.

@toretore
Created January 9, 2016 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toretore/1a7596b63b24aa3af199 to your computer and use it in GitHub Desktop.
Save toretore/1a7596b63b24aa3af199 to your computer and use it in GitHub Desktop.
require 'socket'
server1 = TCPServer.new('0.0.0.0', 1337)
server2 = TCPServer.new('0.0.0.0', 1338)
servers = [server1, server2]
clients = []
loop do
readables, * = IO.select(servers+clients)
readables.each do |sock|
if sock.is_a?(TCPServer)
puts 'Connection'
clients << sock.accept
else
puts 'Client'
sock.puts(sock.gets)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment