1
votes

I want to setup a topology where a worker's IP address is unknown, but only a central broker's address is known. Thus I am trying to bind with a dealer, and connect with rep. But rep never gets my messages:

Using Python3.

Process 1:

import zmq
context = zmq.Context()
sock = context.socket(zmq.DEALER)
sock.bind("tcp://127.0.0.1:55597")

Process 2:

import zmq
context = zmq.Context()
sockrep = context.socket(zmq.REP)
sockrep.connect("tcp://127.0.0.1:55597")

Now if I send a message from Process 1:

sock.send(b"hello")

Process 2 locks up:

sockrep.recv() #..............blocks forever

Is there any way I can make the above pattern work? Am I in need of other socket types or another topology? I can get it working fine with DEALER DEALER but then I have two fully async sockets and that's not what I want. To reiterate, there is only ONE known IP address and that is the one of the computer making the requests, not those filling the requests (these have to connect to the binded requestor).

1

1 Answers

2
votes

When sending from DEALER to REP you need to prefix your message with an empty frame (as REP has support for messages that have been through ROUTER sockets, so it strips of all frames until the empty frame)