[zeromq-dev] Reliable REP-REQ server

Omar Álvarez omar.alvarez at cinfo.es
Mon Mar 4 19:52:06 CET 2019

First of all, I am using ZeroMQ 4.2.2 and Ubuntu 18.04.

I am trying to implement a reliable server in the REP-REQ model. I have
implemented exception handling for proper server shutdown and I detect when
a REP socket enters the infamous invalid state (EFSM operation cannot be
performed on this socket at the moment due to the socket not being in the
appropriate state).

I have a standard python client, that I exit using ctrl-c to create a
non-clean exit, which leaves the socket in an invalid state. I then try to
reconnect executing the client again.

When I try to follow the same design as in the "lazy pirate pattern", when
I know the socket is in an invalid state; I try to close the socket, create
a new one and then bind it again to the same IPC endpoint. When I do this,
the error does not pop up again, but the recv() call blocks indefinitely
and the client is not able to reach the server anymore.

This is my current server code:


I have tried closing the socket before deleting the pointer. Closing both
the context and the socket and deleting both of them. The best I have been
able to achieve is being able to connect a second time. But from the third
time on, there is no way of recovering the socket. I have also tried
polling the socket before the recv() call and it is also a no go.

Is there a mistake in my code? How can deleting and recreating context and
socket not work after doing it two times (it should be the same as
executing the server again)? Any recommendations for having a reliable
server (even when messages can be dropped while being transmitted)?

Thanks in advance to everybody, I have been trying to solve this problem
for a while and I am stuck.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20190304/7a3db180/attachment.htm>

More information about the zeromq-dev mailing list