[zeromq-dev] ZMQ_STREAM identity problem

Chris Laws clawsicus at gmail.com
Wed Oct 30 12:20:27 CET 2013

I am investigating bridging applications that will allow non-zmq parts of
my system to communicate with the ZMQ parts. Consequently I am playing
around with ZMQ_STREAM sockets in both client and server scenarios.

I have run into a problem when using CZMQ because the zsocket_identity
function is returning a char* for what is really just some binary identity
data. When I try to place this into the first zframe (used by the
ZMQ_STREAM socket to route the message) I use something along the lines of:

rc = zsocket_connect (sock, "tcp://");
char *identity = zsocket_identity (sock);

and then later:

// Supply ZMQ with the identity to route the message to.
frame = zframe_new (identity, strlen(identity));
zframe_send (&frame, sock, ZMQ_SNDMORE);

The strlen is returning 0 because the identity is really binary and often
(for me at least) the first char is 0 which causes strlen to return 0.
Consequently the identity passed in the zframe is bogus and the message is

Can anyone suggest a better way to achieve this. I'm trying to use CZMQ
because I like and prefer it but I guess I could mix in libzmq calls such

// get the identity old-school style
uint8_t id [256];
size_t id_size = 256;
rc = zmq_getsockopt (sock, ZMQ_IDENTITY, id, &id_size);

which would provide the correct size when I create the frame holding the

Alternatively, perhaps the zsocket_identity CZMQ function could be changed
so that a size_t is passed into the function and gets updated with the
actual identity size?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20131030/e0fa1abc/attachment.htm>

More information about the zeromq-dev mailing list