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

时间:2016-10-30 07:51:25

标签: stream zeromq

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

  1. 为什么第二次recv为0?它来自哪里?
  2. 感谢您的帮助

    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 /\n\n", 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] = '\0';
        cout <<"forth  recv "<<  buffer<< "rc = "<< rc<<endl;
    }
    

1 个答案:

答案 0 :(得分:0)

我在zmq :: stream_engine_t :: plug中得到了它 对于原始套接字,将初始0长度消息发送到应用程序,以便它知道对等方已连接。