zeromq / cppzmq

Header-only C++ binding for libzmq
http://www.zeromq.org
MIT License
1.95k stars 757 forks source link

ZMQ_HELLO_MSG doesn't work #625

Open wsehjk opened 9 months ago

wsehjk commented 9 months ago

Please use this template for reporting suspected bugs or requests for help.

Issue description

server socket (router mode) set the ZMQ_HELLO_MSG, but the client (dealer mode) cannnot receive this msg, even though netstat says connection has been established.

Environment

Minimal test code / Steps to reproduce the issue

  1. 
    #define ZMQ_BUILD_DRAFT_API
    #include <iostream>
    #include <zmq.hpp>

int main() { zmq::context_t server_ctx; zmq::context_t client_ctx;

zmq::socket_t server(server_ctx, zmq::socket_type::router);
zmq::socket_t client(client_ctx, zmq::socket_type::dealer);
zmq_setsockopt(server, ZMQ_HELLO_MSG, "hello", 5);

client.setsockopt(ZMQ_RCVTIMEO, 80000); // 500ms

server.bind("tcp://127.0.0.1:5555");
client.connect("tcp://127.0.0.1:5555");
zmq::message_t msg;

while (true) {
    client.recv(msg);
    if (!msg.empty()) {
        std::string str(msg.to_string());
        std::cout << str << std::endl;
        break;
    }
}
return 0;

}



# What's the actual result? (include assertion message & call stack if applicable)
should print `hello`

# What's the expected result?
program stuck in the `while` loop