[zeromq-dev] recv in REQ client blocks forever if XREP server dies

Troy Gutjahr zmq-devlist at troy.cygnusconnect.com
Sun Dec 5 08:46:37 CET 2010

Thanks for the quick response, Martin.

recv is not expected to fail if the server that has bound to the
endpoint dies? The only way to for the client to detect that situation
is by using poll with a timeout? This is not the behaviour that I would
have expected and so I spent the last two days reading the
documentation, experimenting and endlessly searching the devlist
archives trying to find out what I was doing wrong. :-)

I think you are saying that I would have to write my client code like

send the request to the XREP server
poll the REP socket with a timeout
if event from REP socket
   recv the response from the server
else if timeout
   handle the failure of the request and get ready to send another

Is that right?


-- Troy

On Sun, 05 Dec 2010 08:29 +0100, "Martin Sustrik" <sustrik at 250bpm.com>
> Troy,
> > I want to develop a reconnection strategy in my client program so that
> > whenever the XREP server terminates and restarts, the client will get an
> > error and then repeatedly retry connecting to the server. Alternatively,
> > I would like the new instance of the server to take over the previously
> > established XREP end of the connection and start handling the next
> > request from the clients.
> 0MQ does reconnect for you. No need for any assistance from your side. 
> Same for two servers problem. Just connect the client to both servers.
> The only thing not implemented at the moment is request resend when it 
> is lost due to server failure.
> To implement that use zmq_poll(timeout) to wait for a reply and resend 
> the request once the timeout is reached.
> Martin

More information about the zeromq-dev mailing list