Last active
January 28, 2016 12:21
-
-
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.
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 '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