futzing with an eventmachine version of ping pong server
This commit is contained in:
parent
0aaab6db1c
commit
277857fe4b
26
ruby-sockets/ping-pong-em-server.rb
Normal file
26
ruby-sockets/ping-pong-em-server.rb
Normal file
@ -0,0 +1,26 @@
|
||||
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
|
||||
|
||||
EventMachine::run do
|
||||
EventMachine::start_server('0.0.0.0', 24000, PongServer)
|
||||
puts 'Listening on 0.0.0.0:24000'
|
||||
end
|
Loading…
Reference in New Issue
Block a user