Skip to content

Instantly share code, notes, and snippets.

@jqr
Created February 7, 2012 03:23
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 jqr/1756938 to your computer and use it in GitHub Desktop.
Save jqr/1756938 to your computer and use it in GitHub Desktop.
ZeroMQ push/pull example

For fun, try running client before the server.

require 'rubygems'
require 'zmq'
# reference http://zguide.zeromq.org/rb:taskwork
context = ZMQ::Context.new
pull = context.socket(ZMQ::PULL)
pull.connect 'tcp://127.0.0.1:5555'
while line = pull.recv
puts line
end
require 'rubygems'
require 'zmq'
# reference http://zguide.zeromq.org/rb:taskvent
context = ZMQ::Context.new
push = context.socket ZMQ::PUSH
push.bind 'tcp://*:5555'
i = 0
loop do
push.send "example message #{i+=1}"
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment