On Sep 19, 2010, at 8:00 AM, liyongyan wrote:

> Can I ask another question?
> I use the zmq_poll() in REQ-REP pattern
> When the client send a Req and then wait for res from the server ,
> but the Res can not reach the client in time for some reasons(for example, 
> handle the Req for a long time),
> then the client wait timeout, now how to handle the socket?
> If I call the zmq_close()  and  next time when send a Req I build another 
> socket and connect server again,
> what happen after the server send the delayed Res? What will server do in ZMQ 
> with the former connection to the client?
>  Will the server release the related resource assigned to the former 
> connection?

Timeouts are not handled by 0mq. You must create the logic in your application 
to deal with these issues yourself.

This may be covered in the user guide. Check http://zguide.zeromq.org/chapter:1

If not, here is how I would suggest you try to handle this in your application.

1. Use a XREP socket on your server. The XRE? sockets do *not* enforce a strict 
send/recv ordering like the REQ/REP sockets.

2. After you call zmq_close() on the original REQ socket that timed out, make 
sure that the *new* REQ socket you build has the same identity as the old one. 
I *think* 0mq will honor that (use zmq_setsockopt(IDENTITY, x) to set it) for 
routing a delayed response back to you. Again, your application will need to 
know how to handle a delayed response.

3. When you call zmq_close() on a socket now, any messages in progress will be 
dropped. 0mq releases all resources associated with the now dead socket.

cr


_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to