为什么zmq_stream客户端需要recv四次才能获得实际数据



9070端口是简单的HTTP服务器(tcp不带zmq)
我有一个问题:

  1. 为什么第二个接收值是0?它从哪里来的?

thanks for help

void test_stream_to_tcp()
{
    uint8_t id [256];
    size_t id_size = 256;
    uint8_t buffer [256];
    void *ctx = zmq_ctx_new ();
    void *client = zmq_socket (ctx, ZMQ_STREAM);
    int rc = 0;
    rc = zmq_connect (client, "tcp://localhost:9070");
    rc = zmq_getsockopt (client, ZMQ_IDENTITY, id, &id_size);
    rc = zmq_send (client, id, id_size, ZMQ_SNDMORE);
    rc = zmq_send (client, "GET /nn", 7, 0);
    assert (rc == 7);
    rc = zmq_recv (client, buffer, 256, 0);
    cout <<"first recv "<<  buffer << "rc = "<< rc<<endl;
    rc = zmq_recv (client, buffer, 256, 0);
    cout <<"second recv "<<  buffer<< "rc = "<< rc<<endl;
    rc = zmq_recv (client, buffer, 256, 0);
    cout <<"third recv "<<  buffer<< "rc = "<< rc<<endl;
    rc = zmq_recv (client, buffer, 256, 0);
    buffer[rc] = '';
    cout <<"forth  recv "<<  buffer<< "rc = "<< rc<<endl;
}

我明白了,在zmq::stream_engine_t::plug对于原始套接字,向应用程序发送一个初始长度为0的消息,以便它知道对等端已经连接。

相关内容

  • 没有找到相关文章

最新更新