Skip to content

Instantly share code, notes, and snippets.

@meetme2meat
Last active January 28, 2016 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meetme2meat/15bbe6541dabd9d986b0 to your computer and use it in GitHub Desktop.
Save meetme2meat/15bbe6541dabd9d986b0 to your computer and use it in GitHub Desktop.
Using the server2.rb as the server for the 2 clients does not yield parallelism.
require 'celluloid/zmq'
require 'colorize'
Celluloid::ZMQ.init
class Server
include Celluloid::ZMQ
def initialize()
@socket = Socket::Pull.new
begin
@socket.bind('tcp://192.168.1.10:3435')
rescue IOError
@socket.close
raise
end
end
def run
loop { async.handle_message @socket.read }
end
def handle_message(message)
DisplayMessage.message(message)
end
end
class DisplayMessage
def self.message(message)
puts "Received at #{Time.now.strftime('%I:%M:%S %p')} and message is #{message}"
## Intentionally added sleep to test whether Celluloid block the main process for 60 seconds or not.
if message == 'client-1'
puts 'Going to sleep now'.red
sleep 60
end
end
end
server = Server.new()
server.async.run
sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment