Skip to content

Instantly share code, notes, and snippets.

@meetme2meat
Last active January 28, 2016 12:20
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/01d8ab8c6e8e81129729 to your computer and use it in GitHub Desktop.
Save meetme2meat/01d8ab8c6e8e81129729 to your computer and use it in GitHub Desktop.
the server-1 shamelessly copied from Celluloid-ZMQ README.md
## 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