Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting the topic when using the pyobj subfunctions in zeromq/python

Tags:

python

zeromq

I have been looking at zeromq and i noticed there were socket.send_pyobj() and socket.recv_pyobj() functions.

My question is how would one set the topic for PUB/SUB if they called this. In the examples i have seen that have used the regular send it was always two strings with a space in between and first string would be considered a topic.

topic = 'test'
msg = 'hello'
socket.send("%s %s" % (topic,msg))

Is there a way? Or maybe should i use different ports as a way to make different topics?

like image 255
PHGamer Avatar asked Jul 31 '26 12:07

PHGamer


1 Answers

NVM. figured out how to do it. I should use send_multipart if i want the topic and msg viewed as one and also filter the object.

For the publisher.

   self.socket.send_multipart([b'status',pickle.dumps(msg2)])

For the reciver.

    socket.setsockopt(zmq.SUBSCRIBE, 'status')
    [topic,msg] = socket.recv_multipart()
    msg2 = pickle.loads(msg)
    print msg2['game']

I don't know why but if you use their example. http://zguide.zeromq.org/py:psenvsub it shows i should do b'status' on the socketopt but it didnt filter if i did it that wya.

like image 106
PHGamer Avatar answered Aug 02 '26 21:08

PHGamer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!