[zeromq-dev] Reconnecting the Client side of a REQ-REP socket
Luca Boccassi
luca.boccassi at gmail.com
Fri Mar 23 14:43:20 CET 2018
On Fri, 2018-03-23 at 08:54 -0400, Jasper Jaspers wrote:
> On the client side there are two threads. Thread1 continually issues
> the
> zmq_send followed by zmq_recv. Thread2 detects that the endpoint has
> changed. When thread2 detects the endpoint has changed I'd like to
> unblock
> thread1 that's currently waiting for zmq_recv to finish. Is it
> possible to
> have thread2 issue a zmq_disconnect to unblock the zmq_recv in
> thread1?
No, only the new thread-safe sockets can be used from multiple threads
- what you can do is add inproc zmq_pair sockets between thread1 and
thread2, and then instead of doing zmq_recv do zmq_poll in thread1 on
both the req socket and the inproc one - that way the poll will be
interrupted when thread2 sends the updated endpoint, and you can take
it from there in thread 1 (disconnect/connect).
> On Fri, Mar 23, 2018 at 7:36 AM, Luca Boccassi
> <luca.boccassi at gmail.com>
> wrote:
>
> > On Thu, 2018-03-22 at 21:53 -0400, Jasper Jaspers wrote:
> > > In my application (C++ / Linux / zeromq 4.2) there are several
> > > sockets
> > > within a single context. Some of the REQ-REP sockets have
> > > transient
> > > servers and the clients need to be reconnected gracefully and
> > > quickly
> > > when
> > > the servers change. I'm having problems reconnecting the client
> > > side
> > > of
> > > the REQ-REP socket when the server side changes. The client's
> > > REQ
> > > socket
> > > is stuck waiting for a reply from the server's REP socket that it
> > > never
> > > gets.
> > >
> > > I have a way of notifying the client that the server has changed
> > > and
> > > it
> > > needs to reconnect, however I don't know how to unblock the
> > > client's
> > > receive call ( waiting for the reply). I do have a timeout set
> > > on
> > > receive
> > > call but I'd like to have the client reconnect a lot sooner than
> > > waiting
> > > for the timeout to expire before reconnecting. I see that
> > > calling
> > > zmq_term() on the context should unblock the receive call, but I
> > > can't use
> > > that since I have other connected sockets within the context that
> > > I
> > > don't
> > > want to disrupt. Does anyone have a suggestion on how to resolve
> > > this?
> >
> > If the endpoint stays the same look at the heartbeats options.
> > If the endpoint changes, you'll need to zmq_disconnect and
> > zmq_connect
> >
> > --
> > Kind regards,
> > Luca Boccassi
> > _______________________________________________
> > zeromq-dev mailing list
> > zeromq-dev at lists.zeromq.org
> > https://lists.zeromq.org/mailman/listinfo/zeromq-dev
> >
> >
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
--
Kind regards,
Luca Boccassi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20180323/e607c9c0/attachment.sig>
More information about the zeromq-dev
mailing list