From 277857fe4b1bc01869d8777c23953d8aed833a56 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Fri, 15 Jun 2012 10:02:12 -0400 Subject: [PATCH] futzing with an eventmachine version of ping pong server --- ruby-sockets/ping-pong-em-server.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ruby-sockets/ping-pong-em-server.rb diff --git a/ruby-sockets/ping-pong-em-server.rb b/ruby-sockets/ping-pong-em-server.rb new file mode 100644 index 0000000..9ba0823 --- /dev/null +++ b/ruby-sockets/ping-pong-em-server.rb @@ -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