Skip to content

Instantly share code, notes, and snippets.

@phil
Created June 11, 2014 13:15
Show Gist options
  • Save phil/21f6e3dd1e7da7b0625b to your computer and use it in GitHub Desktop.
Save phil/21f6e3dd1e7da7b0625b to your computer and use it in GitHub Desktop.
Very Basic EM Echo Server
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