Skip to content

Instantly share code, notes, and snippets.

@lucky
Created November 4, 2010 19:01
Show Gist options
  • Save lucky/662973 to your computer and use it in GitHub Desktop.
Save lucky/662973 to your computer and use it in GitHub Desktop.
# Why did I ever write this?
require 'rubygems'
require 'eventmachine'
module MyClient
def receive_data data
puts "Got back: #{data}"
end
def unbind
puts "terminated connection"
end
end
EM.run {
EM.epoll
Signal.trap("INT") { EM.stop }
client = EM.connect "0.0.0.0", 10000, MyClient
EM.add_timer(2) { puts "a"; client.send_data Marshal.dump({:a => 1}) }
EM.add_timer(2) { puts "b"; client.send_data Marshal.dump({:b => 2}) }
EM.add_timer(2.1) { puts "c"; client.send_data Marshal.dump({:c => 3}) }
}
puts "END END END"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment