cppzmq icon indicating copy to clipboard operation
cppzmq copied to clipboard

set routing_id cause recv does not work

Open soroshsabz opened this issue 5 years ago • 3 comments

ITNOA

Hi,

I have client socket like below

       string address = "tcp://";
       address += ip_address;
       address += ":";
       address += to_string(port);

       socket = new zmq::socket_t(get_context_instance(), ZMQ_DEALER);

       set_socket_linger_period();

       // A random id will be used if id is not set
       if (id != "") socket->set(zmq::sockopt::routing_id, id);

and send a message with this socket like below

        zmq::message_t zmq_message(message_size);
        memcpy(zmq_message.data(), message, message_size);

        return socket->send(zmq_message);

and have server socket like below

        string endpoint = "tcp://";
        endpoint += interface_name;
        endpoint += ":";
        endpoint += to_string(port);

        socket = new zmq::socket_t(get_context_instance(), ZMQ_ROUTER);

and receive from server socket like below

        zmq::message_t id;
        if (!socket->recv(&id, 0)) return 0;
        last_caller_id = string(static_cast<char*>(id.data()), id.size());

        zmq::message_t reply;
        if (!socket->recv(&reply, 0)) return 0;

My problem is when id is does not set (empty string) send and receive work correctly, but when I set id to some string like "FOO_BAR_ID" receive method does not work and first recv (recv of id) does not finish and blocking infinite.

So my question is, what is my problem and how to resolve this?

I use latest version of cppzmq and libzmq 4.3.2 on Ubuntu 20.04.1

I have ask this question on stackoverflow

thanks a lot

soroshsabz avatar Sep 27 '20 13:09 soroshsabz

Can you try using the non-deprecated send/recv functions. And can you also provide how you send the data?

gummif avatar Sep 30 '20 14:09 gummif

What is non-deprecated API?

soroshsabz avatar Sep 30 '20 19:09 soroshsabz

The functions that are not marked as deprecated, the deprecated ones are easier to misuse.

gummif avatar Oct 01 '20 10:10 gummif