Skip to content

Instantly share code, notes, and snippets.

@rkh
Created July 24, 2011 16:47
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rkh/1102809 to your computer and use it in GitHub Desktop.
Save rkh/1102809 to your computer and use it in GitHub Desktop.
require 'eventmachine'
require 'socket'
require 'kgio'
server = Kgio::TCPServer.new('0.0.0.0', 4242)
module Dispatch
def notify_readable
io = @io.kgio_tryaccept or return
EventMachine.attach(io, Server)
end
end
module Server
def receive_data(data)
puts Process.pid.to_s << " " << data
close_connection
end
end
3.times do
fork { EM.run { EM.watch(server, Dispatch) { |c| c.notify_readable = true }}}
end
Process.waitall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment