[zeromq-dev] Fundamentals of a REQ/REP

Daniel Hyams dhyams at gmail.com
Fri Sep 30 22:53:53 CEST 2011


What I'm about to ask is so basic (very green to sockets and ZMQ), I have to
be misunderstanding something fundamental :(  But I have been through the
guide and searched the archives, and have not come up with a good answer for
this.

All I'm trying to do is have a server and client talk back and forth with a
REQ/REP pattern.  (Client REQ, Server REP).  As long as the server side is
up, everything is fine.

But, what happens on the client end is unsavory, if the server is down.
 What I would like to happen is for the client to be able to tell the user
"hey, the server is down, and your request isn't going to happen" if the
server does not respond to a REQ.  I cannot seem to make this happen....

If the client does (in Python):
  sock.send("the reqeust")
  reply = sock.recv()
then this deadlocks when the servers is down, obviously.

If the client does:
  sock.send("the request")
  poller = zmq.Poller();
  poller.register(sock.zmq.POLLIN)
  socks = dict(poller.poll(1000))
  if sock in socks:
      reply = sock.recv()
  else:
      print "The server is not alive"
      # oops, now the lockstep send/recv required for a REQ/REP setup is
broken!
      # socket is in the wrong state for a send.

Then I get into trouble also, because the socket gets in the wrong state...I
want to send next, not receive.  But I don't see any way of forcing the
socket back into a "sending" state.

I also tried a PAIR instead of REQ/REP, and did much better with that one,
but since ZMQ queues messages on the sending end, my server gets all of the
(undesired) queued up messages upon startup, and the client is not ready to
receive the resulting replies.

So I'm mystified.  Is the answer a ROUTER/DEALER setup?

-- 
Daniel Hyams
dhyams at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110930/a5e8d8a0/attachment.htm>


More information about the zeromq-dev mailing list