Skip to content

Instantly share code, notes, and snippets.

@ewoodh2o
Created March 29, 2012 22:10
Show Gist options
  • Save ewoodh2o/2244245 to your computer and use it in GitHub Desktop.
Save ewoodh2o/2244245 to your computer and use it in GitHub Desktop.
ZMQ Push/Pull Exploration
require 'rubygems'
require 'zmq'
context = ZMQ::Context.new
# Start listening
pull = context.socket(ZMQ::PULL)
pull.bind("tcp://127.0.0.1:5555")
# Get updates, exit on ^C
begin
while line = pull.recv
puts line
end
rescue Exception => e
end
pull.close
require 'rubygems'
require 'zmq'
context = ZMQ::Context.new
push = context.socket(ZMQ::PUSH)
push.connect("tcp://127.0.0.1:5555")
# Send block of messages, or default to one at a time
count = ARGV[0].to_i || 1
# Broadcast 20 updates, sleeping between
20.times do |i|
count.times do |j|
push.send("Update #{i}.#{j}")
end
sleep(1)
end
push.send("END")
push.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment