Created
June 11, 2014 13:15
-
-
Save phil/21f6e3dd1e7da7b0625b to your computer and use it in GitHub Desktop.
Very Basic EM Echo Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'eventmachine' | |
class EchoServer < EM::Connection | |
def post_init | |
puts "-- someone connected to the echo server!" | |
EM.add_periodic_timer 5 do | |
send_data "Foo Bar" | |
end | |
end | |
def receive_data data | |
send_data ">>> you sent: #{data}" | |
end | |
end | |
EventMachine::run do | |
EventMachine::start_server "127.0.0.1", 8081, EchoServer | |
puts 'running echo server on 8081' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment