Skip to content

Instantly share code, notes, and snippets.

Created April 16, 2019 01:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Example PUB/SUB from PyZMQ
import zmq
import sys,os,time
port = '5563'
def server():
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind('tcp://*:%s' % port)
while True:
socket.send_multipart([b"A", b"We don't want to see this"])
socket.send_multipart([b"B", b"We would like to see this"])
def client():
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect('tcp://localhost:%s' % port)
socket.setsockopt(zmq.SUBSCRIBE, b"B")
while True:
[addr, data] = socket.recv_multipart()
print('[%s]: %s' % ( addr, data ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment