[zeromq-dev] Multithreaded server, delivers message in one direction

tlrx tlrx.dev at gmail.com
Tue Oct 25 17:44:44 CEST 2011


Thanks again Chuck.

The REP is a mistake, it was ZMQ.XREP but i desparetly tried with something
else (REP for this copy/paste).

I checked the Java examples again but there is no example that follows a
XREQ ROUTER DEALER QUEUE XREP pattern.

In the Java example, sometimes a empty string is send (
https://github.com/imatix/zguide/blob/master/examples/Java/lruqueue.java)
 sometimes no null/empty string is sent at all (
https://github.com/imatix/zguide/blob/master/examples/Java/rtdealer.java).
In the REP example, sometimes the last byte of the message is set to zero.

I tried the previous code with XREP and replying an empty string, but the
problem is still here. I'm definitely missing something...

Tanguy


Le 25 octobre 2011 15:26, Chuck Remes <cremes.devlist at mac.com> a écrit :

> Comments inline.
>
> On Oct 25, 2011, at 3:20 AM, tlrx wrote:
>
> I've read the doc, which is clear and confirms my previous understanding,
> but I still have the problem.
>
> I think I am missing something... Here's my Java code for the XREP:
>
>
> public void run() {
>
> ZMQ.Socket socket = context.socket(ZMQ.REP);
>
>
> You said you wanted an XREP socket, but your code shows you are using a REP
> socket. The REP socket manages the construction of the envelope for you so
> doing it yourself won't work.
>
>  socket.connect("inproc://workers");
>  while (true) {
>
> List<byte[]> parts = new ArrayList<byte[]>();
>
> do {
> byte[] request = socket.recv(0);
> parts.add(request);
>  }while (socket.hasReceiveMore());
>
> // Send back all the socket identities
>
> for(int i=0; i<(parts.size() - 1); i++){
> socket.send(parts.get(i), ZMQ.SNDMORE);
>  }
>
> // Do I need to send a <null part message> here?
>
>
> // Send the reply message
>
> String reply = "See you " + this.toString();
>  socket.send(reply.getBytes(), 0);
> }
> }
>
>
> Does the lib automatically send the <null message part> if I use
> socket.send(.., 0)?
>
>
> For a REP socket, the library knows how to make the envelope and pad it
> with a null message part. If you were using an XREP socket, it should be
> sufficient to send an empty string as the null message part.
>
> Take a look at the Java example code in the zguide [1]. It has code
> examples for over a dozen languages. Hopefully there is at least one in Java
> that shows how to use XREP sockets.
>
> cr
>
> [1] https://github.com/imatix/zguide
>
>
> cr
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111025/01e1858c/attachment.htm>


More information about the zeromq-dev mailing list