[zeromq-dev] python and pub/sub, don't see packets going out

Jerry Scharf scharf at lagunawayconsulting.com
Wed Mar 2 02:18:58 CET 2016


Hi,

I have req/rep working fine now. There is one deviation from the pyzmq 
documentation. The documentation says that you use socket.send with a 
string, but the code errors out and says use send_string instead. I 
don't know if this is a version problem in the zmq I built, but I just 
did pip install pyzmq.

Now I am trying to make pub/sub work and am stuck again. Here's my 
trivial server:

import zmq

zc = zmq.Context()
pubsock = zc.socket(zmq.PUB)
pubsock.bind("tcp://*:12345")

for i in range(10):
     msg = "topic sending message {}".format(i)
     pubsock.send_string(msg)

and here's my trivial client:
import zmq

zc = zmq.Context()
subsock = zc.socket(zmq.SUB)
subsock.connect("tcp://localhost:12345")

for i in range(10):
     message = subsock.recv_string()
     print("{}\n".format(message))

print("got 10\n")


The client sits happily waiting for the packets that never come. When I 
watch this with tcpdump, I see a bunch of packets go back and forth 
during the connect but no packets come out when I do the send_string. 
The same symptoms are true both on the raspberry pi and a ubuntu machine.

Any clue what is going on?

jerry





More information about the zeromq-dev mailing list