0

I am trying to implement an inter-process communication.

The model: Part A -> Sends messages to Part B.

I have implemented this using Client-Server example from ZMQ tutorial (code attached bellow), but facing issues that the process is "locked".

What is the best practice to implement this kind of model?

It is not classic "Client-Server". Actually just one part sends data to the second part, and second part uses it.

Is there an option to send a message with a timeout, that it will not lock the process?

Any input / example will be very appreciated!

Server:

zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REP);
socket.bind("tcp://*:5555");
..
socket.recv(&request);                              // SERVER.receives first
socket.send(reply);                                 // SERVER.sends next to Client
..                                                  //       .analyze .recv'd data

Client:

requester = context.socket(ZMQ.REQ);
requester.connect("tcp://localhost:5555");
requester.send(str.getBytes(), 0);                 // CLIENT.sends
byte[] reply = requester.recv(0);                  // CLIENT.receives
user3666197
  • 1
  • 6
  • 50
  • 92
Yoav
  • 93
  • 1
  • 4
  • 13
  • If the model is that one thing sends and another receives, then you need `push:pull` pair, not `req:rep`. – N.B. Aug 08 '16 at 20:00
  • Yes, it's like that: one side sends -> second receives.Is it possible to add a timeout for this behavior? When Used the req:rep it worked, but got stuck – Yoav Aug 08 '16 at 20:25
  • What would timeout help with? ZMQ can queue (hence the Q in the name) and once the peer is available, it receives the queued messages. If queue memory is exceeded, ZMQ starts dropping older messages. Push-Pull is asynchronous, so I'm not sure what you'd achieve with the timeout here. If you use this asynchronous approach, you shouldn't have a locked process, thus there should be no need for a timeout of any sort. – N.B. Aug 08 '16 at 21:40
  • I used Push-Pull as you advised. The Push part is implemented in Java. If I call the "push string" request including the close part `requster.close(); // ZMQ.Context context` `context.term() //ZMQ.Socket.requester context`- it works well. The problem is that I do not want to open/close socket each time (performance) and should open/close socket once. But seems that finalize() method is not being called -> and in this way all the push data are sent but JVM is hanging and never finished. Any suggestion? (if debugging can see code stuck on: Poller(zmq)) – Yoav Aug 09 '16 at 14:43
  • Don't copy paste those examples.. If you have two processes that are supposed to communicate via ZMQ for an extended period of time, simply open the two sockets, poll to check for the activity and perform work when the message arrived. I'm really not following what's confusing you, don't close the sockets. – N.B. Aug 09 '16 at 20:56
  • I have one process (developed in c++), that invokes Java (JVM). The Java side is actually a Plugin for another Third Party, and is not notified when finished. If for each push I open the socket and as well add the .close() part, it works great. If it is not added, although all logic run - the JVM does not finish (can see it in Process Explorer) and the entire process does not finish (hangs). So I understand that it is a must to use the .close() API at the end? The issue is that I only extent Third Party, and do not know when it finished - so can't add the .close() part "at the end" – Yoav Aug 10 '16 at 07:47
  • Since it is one-way, you can try **`PUSH/PULL`**? Client is push and server is pull – smac89 Oct 26 '19 at 12:41

0 Answers0