Last active
January 28, 2016 12:20
-
-
Save meetme2meat/01d8ab8c6e8e81129729 to your computer and use it in GitHub Desktop.
the server-1 shamelessly copied from Celluloid-ZMQ README.md
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
## Using this as the Celluloid server the client messages are received in parallel. | |
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) | |
puts "Received at #{Time.now.strftime('%I:%M:%S %p')} and message is #{message}" | |
## Intentionally added sleep to test whether Celluloid block the process for 60 seconds. | |
if message == 'client-1' | |
puts 'Going to sleep now'.red | |
sleep 60 | |
end | |
#DisplayMessage.new.message(message) | |
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