[zeromq-dev] Problem with using ROUTER

只和你 843259180 at qq.com
Tue Jun 24 16:59:08 CEST 2014


Hi!‍  I am using ROUTER/DEALER pattern.Here is the use case:I wanna control specific client(DEALER) through sending specific message from server(ROUTER).Here is the client side:


void *context = zmq_ctx_new ();
    void *client = zmq_socket (context, ZMQ_DEALER);
    zmq_setsockopt (client, ZMQ_IDENTITY, "client", 6);         
    zmq_connect (client, "tcp://localhost:5671");
    while (1) 
	{
        char *instruction = s_recv (client);
        if(strcmp(instruction,"kill")==0)
	return 0;
        zmq_close (client);
        zmq_ctx_destroy (context);
        return 0;

        }
Here is the server side:
void *context = zmq_ctx_new ();
    void *server = zmq_socket (context, ZMQ_ROUTER);
    zmq_bind (server, "tcp://*:5671");     
    while (1) 
{
	char clientname[128];
	char instruction[128];
	printf("client name\n");
	scanf("%s",clientname);
	printf("instruction\n");
	scanf("%s",instruction);‍
	s_sendmore(server,clientname);
	s_send(server,instruction);
}
        zmq_close (server);
        zmq_ctx_destroy (context);
        return 0;

For the first time,I can control client through sending message:clientname=client;instruction=kill
But when the client exits and I restart it, I can not send any messages to client.The ID of client did not change .But why can not i send message to it after restarting it???
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140624/52e06f7b/attachment.htm>


More information about the zeromq-dev mailing list