Created
March 6, 2014 03:40
-
-
Save amclain/9381885 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 '0mq' | |
require 'pry' | |
address = 'tcp://127.0.0.1:10000' | |
pull = ZMQ::Socket.new ZMQ::PULL | |
pull.bind address | |
# Push a message after a delay. | |
Thread.new do | |
push = ZMQ::Socket.new ZMQ::PUSH | |
push.connect address | |
sleep 3 | |
push.send_string 'test' | |
sleep 0.1 # Intermittent exception if this is removed. | |
end | |
# Check if pull has any data (it doesn't yet). | |
# (Non-blocking demonstration.) | |
result = ZMQ::Poll.poll_nonblock pull | |
puts "No data available yet." if result.empty? | |
# Do a blocking poll until the pull socket has data. | |
ZMQ::Poll.poll pull do |socket, event| | |
puts socket.recv_string | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment