Skip to content

Instantly share code, notes, and snippets.

@tclarke
Last active May 14, 2019 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tclarke/5247416 to your computer and use it in GitHub Desktop.
Save tclarke/5247416 to your computer and use it in GitHub Desktop.
A sample ZMQ 3.x Python pub/sub example.
import zmq
def publisher():
c=zmq.Context()
s=c.socket(zmq.PUB)
s.bind('tcp://127.0.0.1:1234')
s.send("foobie")
def subscriber():
c=zmq.Context()
s=c.socket(zmq.SUB)
s.setsockopt(zmq.SUBSCRIBE,'')
s.connect('tcp://127.0.0.1:1234')
print s.recv()
def request():
c=zmq.Context()
s=c.socket(zmq.REQ)
s.connect('tcp://127.0.0.1:1234')
s.send("ack")
print s.recv()
def reply():
c=zmq.Context()
s=c.socket(zmq.REP)
s.bind('tcp://127.0.0.1:1234')
print s.recv()
s.send("bar")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment