I have a router-router setup (destination IDs are acquired via a broadcast/response, similar to the Freelance pattern in the ZMQ book).
I've noticed that if my destinations go down and come back up with a new ID, clients can't route to that ID. I'm using 4.0.3. This code demonstrates the issue (on windows - although the Sleep() call is the only platform-specific call). It creates a client and server, sends from client to server, stops the server and starts a new one with the same ID, then stops the server and starts a new with (on the same port) with a different id. The first two sends succeed, the last one fails: #include <zmq.h> #include <zmq_utils.h> #include <iostream> int route_send (void *socket, const char *id, const char *data) { int rc = 0; rc = zmq_send (socket, id, strlen (id), ZMQ_SNDMORE); // server addr if (rc == -1) return 0; rc = zmq_send (socket, "", 0, ZMQ_SNDMORE); // null if (rc == -1) return 0; rc = zmq_send (socket, data, strlen (data), 0); // data if (rc == -1) return 0; return 1; } int route_recv (void *socket) { int rc = 0; char buf[100]; rc = zmq_recv (socket, buf, 100, 0); // client addr if (rc == -1) return 0; printf ("client addr received.\n"); rc = zmq_recv (socket, buf, 100, 0); // null if (rc == -1) return 0; printf ("null received.\n"); rc = zmq_recv (socket, buf, 100, 0); // data if (rc == -1) return 0; buf[rc] = 0; printf ("data received: %s\n", buf); return 1; } int main () { int rc = 0; static void *ctx = zmq_ctx_new (); // server 1 setup void *server = zmq_socket (ctx, ZMQ_ROUTER); rc = zmq_setsockopt (server, ZMQ_IDENTITY, "idserver0001", 12); rc = zmq_bind (server, "tcp://127.0.0.1:30000"); if (rc == -1) { return 1; } // client setup void *client = zmq_socket (ctx, ZMQ_ROUTER); rc = zmq_setsockopt (server, ZMQ_IDENTITY, "idclient0001", 12); if (rc == -1) return 1; rc = zmq_connect (client, "tcp://127.0.0.1:30000"); if (rc == -1) return 1; Sleep (50); printf("sending to server 1\n"); route_send (client, "idserver0001", "test data 1"); printf("receiving in server 1\n"); route_recv (server); rc = zmq_close (server); if (rc == -1) return 1; // server 2 setup void *server2 = zmq_socket (ctx, ZMQ_ROUTER); rc = zmq_setsockopt (server2, ZMQ_IDENTITY, "idserver0001", 12); rc = zmq_bind (server2, "tcp://127.0.0.1:30000"); if (rc == -1) return 1; Sleep (3000); printf("sending to server 2\n"); route_send (client, "idserver0001", "test data 2"); printf("receiving in server 2\n"); route_recv (server2); rc = zmq_close (server2); if (rc == -1) return 1; // server 3 setup void *server3 = zmq_socket (ctx, ZMQ_ROUTER); rc = zmq_setsockopt (server3, ZMQ_IDENTITY, "idserver0003", 12); rc = zmq_bind (server3, "tcp://127.0.0.1:30000"); if (rc == -1) return 1; Sleep (3000); printf("sending to server 3 i (id has changed)\n"); route_send (client, "idserver0003", "test data 2"); printf("receiving in server 3\n"); route_recv (server3); rc = zmq_close (client); if (rc == -1) return 1; rc = zmq_close (server3); if (rc == -1) return 1; rc = zmq_close (client); if (rc == -1) return 1; rc = zmq_ctx_shutdown (ctx); if (rc == -1) return 1; rc = zmq_ctx_destroy (ctx); if (rc == -1) return 1; return 0; } -- Mark Wright markscottwri...@gmail.com
_______________________________________________ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev