Created
September 23, 2012 09:26
-
-
Save bwhite/3769477 to your computer and use it in GitHub Desktop.
ZMQ Pub/Sub Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python zmq_client_sub.py & | |
python zmq_client_sub.py & | |
python zmq_server_pub.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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