box-o-sand/ruby-sockets/ping-pong-server.rb
2012-06-15 09:49:35 -04: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