Skip to content

Instantly share code, notes, and snippets.

@kkleidal
Created October 24, 2014 20:21
Show Gist options
  • Save kkleidal/4a8c7ce3414e120fd9c0 to your computer and use it in GitHub Desktop.
Save kkleidal/4a8c7ce3414e120fd9c0 to your computer and use it in GitHub Desktop.
PyZMQ Basic Pub/Sub Interaction
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
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