Reputation: 1557
I'm following the tutorial here. This is the minimal example to reproduce the problem. After I start the producer process, consumer always complains that "Address already in use". But how can producer and consumer talk to each other if their ports are different? I'm using Python 3 and PyZMQ 16.0.3
Producer
import zmq
context = zmq.Context()
zmq_socket = context.socket(zmq.PUSH)
zmq_socket.bind("tcp://127.0.0.1:5557")
for num in range(2000):
work_message = { 'num' : num }
zmq_socket.send_json(work_message)
Consumer
import zmq
context = zmq.Context()
zmq_socket = context.socket(zmq.PULL)
zmq_socket.bind("tcp://127.0.0.1:5557")
for _ in range(2000):
result = zmq_socket.recv_json()
print(result)
Upvotes: 1
Views: 1960
Reputation: 1557
Ah, nevermind, it should have been zmq_socket.connect
in Consumer, instead of bind
. I'm very new to ZeroMQ, so I thought bind
is the universal idiom.
Hope this helps any other new-comers.
Upvotes: 4