Why does ZeroMQ connect to return 0 even when the server is not listening?

I am using ZeroMQ 3.2 in C. I have a problem when I try to connect to any remote endpoint

void* context = zmq_ctx_new(); void* socket = zmq_socket(context, ZMQ_DEALER); int rc = zmq_connect(socket, addr); 

rc is ALWAYS 0, that is, every thing is OK as indicated by the API . Even if the server is not listening at all.

Did I miss something?

+4
source share
2 answers

Everything is as it should. The advantage (depending on how you look at it, of course) of ZeroMq is that you do not need to connect after starting the server, and also means that it connects normally, even if the connection to the server is temporarily disconnected. ZeroMq will maintain a connection (query) and try again.

Api docs for zmq_connect () state that:

For most modes of transport and sockets, the connection is not made immediately, but if necessary via ØMQ. Thus, a successful call to zmq_connect () does not mean that the connection was or could be established. Because of this, for most types of transport and sockets, the order in which the server socket is attached and the client socket is connected to it does not matter. The first exception is when using the inproc: //: transport, you must call zmq_bind () before calling zmq_connect (). The second exception is ZMQ_PAIR sockets, which do not automatically connect to endpoints.

As you can see from the documentation, there is no error code for the non-responder / existing endpoint. Basically, as long as you provide a valid endpoint (and you, for example, do not fall into the socket limit for a process), you should be good.

+3
source

As the manual says:

Once the node client executes zmq_connect (), the connection exists and that node can start writing messages to the socket. At some stage (I hope, before the messages go down so much that they start to be dropped or client blocks), the server comes to life, makes zmq_bind () and ØMQ begin to deliver messages.

+1
source

All Articles