[zeromq-dev] Retrieve socket identity in REQ-XREP message

Nam-Luc Tran namluc.tran at euranova.eu
Tue Feb 15 15:47:53 CET 2011


Hi,

Following the example from the ZGuide about Request-Reply envelopes
(http://zguide.zeromq.org/chapter:all#toc42), I want to retrieve the
identity of a REQ socket sending to a XREP in Java. Here is the
example code I use :

ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket sink = context.socket(ZMQ.XREP);
sink.bind("tcp://*:5559");

ZMQ.Socket non = context.socket(ZMQ.REQ);
non.connect("tcp://localhost:5559");
non.setIdentity("me".getBytes());
byte[] msg = "message".getBytes();
non.send(msg, 0);
while(true){
byte rec=sink.recv(0);
System.out.println(new String (rec));
if(!sink.hasReceiveMore())
        break;
}
And here the output:
(empty line)
(empty line)
message

As I have understood, the received XREP message should be a multipart
message, with part 1 being the identity of the requester, part 2 is a
white space and part 3 the payload. In the example zhelpers.h is used
to dump the content and the requester identity. How can this be done
in Java?

Best regards,

Nam


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


More information about the zeromq-dev mailing list