خرید بک لینک

Vote count: 0

There is a endpoint which is Dealer. And a endpoint which is Router. The Dealer is coect to Router by TCP protocol. I set the ZMQ_SNDHWM and ZMQ_RCVHWM to 1 all of them. Note that the Dealer is always send to Router. but the Router is not recv.

The question is:

  1. When the Router is not setup, the Dealer just send 1 msg and obstructed. that is right, because the ZMQ_SNDHWM is 1。

  2. But when I setup the Router, the Dealer can continue send about 4K msg and obstructed. Why????

  3. Another, if let Router receive just one msg, the Dealer can continue send about 4K msg again. but it can`t send any more even though the Router continue receive . It seems the Dealer is dead。 Why this happened?

the Dealer code:

// create ctx
void* ctx = zmq_ctx_new();
assert(nullptr != ctx);

// create in
void* in = zmq_socket(ctx, ZMQ_DEALER);
assert(in);
int sndhwm = 1;
assert(0 == zmq_setsockopt(in, ZMQ_SNDHWM, &sndhwm, sizeof(sndhwm)));
assert(0 == zmq_setsockopt(in, ZMQ_RCVHWM, &sndhwm, sizeof(sndhwm)));

int rc = zmq_coect(in, "tcp://127.0.0.1:1012");
assert(!rc);

char content[100] = {0};
int size = 0;
int64_t nCount = 0;
while(1)
{
    sprintf_s(content, "%d", ++nCount);
    size = strlen(content);
    rc = zmq_send(in, content, size, 0);
    assert(rc = size);
    printf("in = %dn", nCount);
}

the Router code:

// create ctx
void* ctx = zmq_ctx_new();
void* out = zmq_socket(ctx, ZMQ_ROUTER);
int sndhwm = 1;
assert(0 == zmq_setsockopt(out, ZMQ_SNDHWM, &sndhwm, sizeof(sndhwm)));
assert(0 == zmq_setsockopt(out, ZMQ_RCVHWM, &sndhwm, sizeof(sndhwm)));

int rc = zmq_bind(out, "tcp://127.0.0.1:1012");
assert(!rc);

while(1)
{

    string cmd;
    cin >> cmd;

    zmq_msg_t msg;
    while(true)
    {
        zmq_msg_init(&msg);
        rc = zmq_recvmsg(out, &msg, 0);
        assert(rc > 0);

        printf("out = %sn", (char*)zmq_msg_data(&msg));
        if(!zmq_msg_more(&msg))
        {
            break;
        }
    }
}

asked 10 secs ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 20 فروردين 1395 ساعت: 10:41

صفحه بندی