Skip to content

Instantly share code, notes, and snippets.

@estan
Created April 5, 2016 13:53
Show Gist options
  • Save estan/6aae102b3ae6b87413b199ef60461622 to your computer and use it in GitHub Desktop.
Save estan/6aae102b3ae6b87413b199ef60461622 to your computer and use it in GitHub Desktop.
from time import sleep
import zmq
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:9001")
while True:
socket.send_json(('vidar', {'foo': 'bar'}))
sleep(1)
import zmq
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect('tcp://localhost:9001')
socket.subscribe = bytes() # Works.
#socket.subscribe = bytes('vidar', 'utf8') # Doesn't work :(
while True:
(topic, message) = socket.recv_json()
print('got {} on topic {}'.format(message, topic))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment