[zeromq-dev] Problem with setsockopt_unicode

Michel Pelletier pelletier.michel at gmail.com
Mon Jan 7 18:18:09 CET 2013


msgpack is formatting your message to a packed format, it does not match
your subscription:


>>> msgpack.packb('netherland')
'\xaanetherland'



On Mon, Jan 7, 2013 at 12:32 AM, Maxa Jean Aimee <maxajeanaimee at yahoo.fr>wrote:

> Hi everyone,
> I would like to solve some problems about publish/subscribe with zeromq
> new version.
> This is a piece of my code
> pub.py
>
> import zmq
> from random import choice
> import msgpack
> context = zmq.Context()
> socket = context.socket(zmq.PUB)
> socket.bind("tcp://127.0.0.1:5000")
>
> countries = ['netherlands','brazil','germany','portugal']
> events = ['yellow card', 'red card', 'goal', 'corner', 'foul']
>
> while True:
>     msg = choice( countries ) +" "+ choice( events )
>     print ("->",msg)
>     msg =msgpack.packb(msg)
>     socket.send( msg )
>
>
> sub.py
>
> import zmq
>
> context = zmq.Context()
> socket = context.socket(zmq.SUB)
> socket.connect("tcp://127.0.0.1:5000")
> socket.setsockopt_unicode(zmq.SUBSCRIBE, "netherlands")
> socket.setsockopt_unicode(zmq.SUBSCRIBE, "germany")
>
> while True:
>     print(socket.recv())
>
>
>
> The problem is when I launch the sub.py to see if i receive my
> subscription correctly, it turned out that i got nothing.
> There is nothing comes out to the ouput.
>
> It should print the result of the subscription, how setsockopt_unicode
> really works ?
>
> It works when i did use the old version of zmq.
>
> It's very confusing !
> Anyhelp would be appreciated
>
>
> Jean Aimé MAXA
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130107/ee690968/attachment.htm>


More information about the zeromq-dev mailing list