Created
July 24, 2011 16:47
-
-
Save rkh/1102809 to your computer and use it in GitHub Desktop.
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' | |
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