[zeromq-dev] ZMQ socket identity.

Vitaliy Ivanov vitaliy at toroki.com
Sat Feb 25 02:39:47 CET 2012


Hi List,

I'm interested in using ZMQ and some custom routing.

For this I'm not trying to use durable sockets but auto generated ZMQ
identities.

To identify sockets I simply want to send a message and collect their
identities.

There is nice example for this in zguide - identity.cpp:

                                        #include <zmq.hpp>
                                        #include "zhelpers.hpp"
                                        
                                        int main () {
                                        zmq::context_t context(1);
                                        
                                        zmq::socket_t sink(context,
                                        ZMQ_ROUTER);
                                        sink.bind( "inproc://example");
                                        
                                        // First allow 0MQ to set the
                                        identity
                                        zmq::socket_t anonymous(context,
                                        ZMQ_REQ);
                                        anonymous.connect( "inproc://example");
                                        
                                        s_send (anonymous, "ROUTER uses
                                        a generated UUID");
                                        s_dump (sink);
                                        
                                        // Then set the identity ourself
                                        zmq::socket_t identified
                                        (context, ZMQ_REQ);
                                        identified.setsockopt( ZMQ_IDENTITY, "Hello", 5);
                                        identified.connect( "inproc://example");
                                        
                                        s_send (identified, "ROUTER
                                        socket uses REQ's socket
                                        identity");
                                        s_dump (sink);
                                        
                                        return 0;
                                        }

And the results of this should be something similar to:

                                        ----------------------------------------
                                        [017] 00314F043F46C441E28DD0AC54BE8DA727
                                        [000]
                                        [026] ROUTER uses a generated UUID
                                        ----------------------------------------
                                        [005] Hello
                                        [000]
                                        [038] ROUTER socket uses REQ's socket identity
                                        
But when I run this I got zero transient socket ID:

                                        $ ./identity 
                                        ----------------------------------------
                                        00[17]00000000000000000
                                        00[0]
                                        00[1c]ROUTER uses a generated UUID
                                        ----------------------------------------
                                        00[5]Hello
                                        00[0]
                                        00[28]ROUTER socket uses REQ's socket identity
                                        
I'm using ZMQ version:

                                        $ ./version 
                                        Current 0MQ version is 2.1.11
                                        
                                        
Can you please advice?

Thanks,
Vitaliy





More information about the zeromq-dev mailing list