Skip to content

Instantly share code, notes, and snippets.

@amclain
Created March 6, 2014 03:40
Show Gist options
  • Save amclain/9381885 to your computer and use it in GitHub Desktop.
Save amclain/9381885 to your computer and use it in GitHub Desktop.
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