Created
October 24, 2014 20:21
-
-
Save kkleidal/4a8c7ce3414e120fd9c0 to your computer and use it in GitHub Desktop.
PyZMQ Basic Pub/Sub Interaction
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 | |
protocol = "tcp" | |
host = "tidmarsh.media.mit.edu" | |
port = "1305" | |
host = "127.0.0.1" | |
port = "5556" | |
# Socket to talk to server | |
context = zmq.Context() | |
socket = context.socket(zmq.SUB) | |
socket.setsockopt(zmq.SUBSCRIBE,'') | |
connect_to = "{}://{}:{}".format(protocol, host, port) | |
print connect_to | |
socket.connect(connect_to) | |
print "connected" | |
while True: | |
print "Blocking, waiting for input..." | |
string = socket.recv() | |
print "Received: ", string |
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 | |
import time | |
port = "5556" | |
context = zmq.Context() | |
socket = context.socket(zmq.PUB) | |
connect_to = "tcp://*:%s" % port | |
print connect_to | |
socket.bind(connect_to) | |
while True: | |
socket.send("Hello World!") | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment