Skip to content

Instantly share code, notes, and snippets.

@bwhite
Created September 23, 2012 09:26
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 bwhite/3769477 to your computer and use it in GitHub Desktop.
Save bwhite/3769477 to your computer and use it in GitHub Desktop.
ZMQ Pub/Sub Example
python zmq_client_sub.py &
python zmq_client_sub.py &
python zmq_server_pub.py
import zmq # Client
sock = zmq.Context().socket(zmq.SUB)
sock.connect("tcp://127.0.0.1:10000")
sock.setsockopt(zmq.SUBSCRIBE, "") # All
while True:
print(sock.recv())
import zmq, time # Server
sock = zmq.Context().socket(zmq.PUB)
sock.bind("tcp://127.0.0.1:10000")
while True:
sock.send(str(time.time()))
time.sleep(.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment