[zeromq-dev] req/rep pattern

Pieter Hintjens ph at imatix.com
Tue Feb 8 09:15:48 CET 2011

On Tue, Feb 8, 2011 at 8:41 AM, Gaspard Bucher <gaspard at teti.ch> wrote:

> Damn ! I found where the problem comes from. Translated in plain C, this is
> what does not work:
> void *requester = zmq_socket (context, ZMQ_REQ);
> zmq_connect(requester, "tcp://localhost:5555");
> zmq_send (requester, &request, 0);
> zmq_connect(requester, "tcp://localhost:7777");
> zmq_send (requester, &request2, 0); /// hang, probably trying to send to
> 5555 ?

Right. This is by design, not a bug: you can connect to multiple
endpoints and the REQ socket will load balance your requests between
those. If one of the endpoints is not bound, it'll wait.

The correct way to use sockets here is to open a new socket (and close
the old one) for each new server. You don't gain anything by 'reusing'
a socket handle.

Pieter Hintjens

More information about the zeromq-dev mailing list