Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
#!/usr/bin/env python

import zmq 

context = zmq.Context()                                                                                                                           
socket = context.socket(zmq.REQ)
socket.connect ("tcp://localhost:50001")
# To subscribe
socket.send_json({"sub": ["bonjour"]})
# To unsubscribe
# socket.send_json({"unsub": ["bonjour"]})
# you can even do both
# socket.send_json({"sub": ["Hello"], "unsub": ["bonjour"]})
message = socket.recv()
print(message) # You will get the subscriptions of the PUB socket {"subscriptions":["Hello"]}

Once this is set up, you can receive messages using a snippet of code similar to this :

...