box-o-sand/oldstuff/ruby-sockets/ping-pong/server.rb
2015-06-22 13:15:42 -05:00

16 lines
312 B
Ruby

require 'socket'
server = TCPServer.new('0.0.0.0', 24000)
loop do
Thread.start(server.accept) do |client|
if (ping = client.gets) =~ /PING/
puts 'server: RECV PING'
client.puts("PONG\n")
else
puts "server: RECV #{ping}"
client.puts("NOPE\n")
end
client.close
end
end