Skip to content

Instantly share code, notes, and snippets.

@FirefoxMetzger
Last active July 2, 2017 10:42
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 FirefoxMetzger/c65c31a25889ff7e753cf53dae70954b to your computer and use it in GitHub Desktop.
Save FirefoxMetzger/c65c31a25889ff7e753cf53dae70954b to your computer and use it in GitHub Desktop.
PUB + bind - then - SUB + connect
import zmq
context = zmq.Context()
address = "inproc://test"
#publisher
pub = context.socket(zmq.PUB)
pub.bind(address)
#subscriber
sub = context.socket(zmq.SUB)
sub.connect(address)
sub.setsockopt(zmq.SUBSCRIBE, "test")
poller = zmq.Poller()
poller.register(sub, zmq.POLLIN)
#send some messages
pub.send("test 123")
pub.send("test 345")
pub.send("foo 23")
pub.send("test hello")
# retrieve
has_next = True
while has_next:
has_next = False
sock = dict(poller.poll(100))
if sub in sock:
has_next = True
msg = sub.recv()
print msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment