Created
March 29, 2012 22:10
-
-
Save ewoodh2o/2244245 to your computer and use it in GitHub Desktop.
ZMQ Push/Pull Exploration
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 '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 |
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 '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