Skip to content

Instantly share code, notes, and snippets.

@bwhite
Created Sep 23, 2012
Embed
What would you like to do?
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