Created
September 10, 2011 18:07
-
-
Save ericsaboia/1208584 to your computer and use it in GitHub Desktop.
Eventmachine server example
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 'eventmachine' | |
module EchoServer | |
def post_init | |
puts "-- someone connected to the echo server!" | |
end | |
def receive_data data | |
send_data ">>>you sent: #{data}" | |
close_connection if data =~ /quit/i | |
end | |
def unbind | |
puts "-- someone disconnected from the echo server!" | |
end | |
end | |
EventMachine::run { | |
EventMachine::start_server "127.0.0.1", 8081, EchoServer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment