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

Chuck Remes cremes.devlist at mac.com
Tue Oct 25 15:26:34 CEST 2011


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111025/b9d3fdea/attachment.htm>


More information about the zeromq-dev mailing list