box-o-sand/ruby-sockets/ping-pong/server.rb

16 lines
312 B
Ruby
Raw Normal View History

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