2012-06-15 14:02:12 +00:00
|
|
|
require 'eventmachine'
|
|
|
|
|
|
|
|
module PongServer
|
|
|
|
def post_init
|
|
|
|
puts "server: Got me a client!"
|
|
|
|
end
|
|
|
|
|
|
|
|
def receive_data(data)
|
|
|
|
if data =~ /PING/
|
|
|
|
puts 'server: RECV PING'
|
|
|
|
send_data("PONG\n")
|
|
|
|
else
|
|
|
|
puts "server: RECV #{data}"
|
|
|
|
send_data("NOPE\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unbind
|
|
|
|
puts "server: So long, client!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-16 04:41:44 +00:00
|
|
|
EventMachine.run do
|
|
|
|
EventMachine.start_server('0.0.0.0', 24000, PongServer)
|
2012-06-15 14:02:12 +00:00
|
|
|
puts 'Listening on 0.0.0.0:24000'
|
|
|
|
end
|