[zeromq-dev] Sub drop messages
Jiecong Li
lijiecong at gmail.com
Thu Jan 15 03:56:49 CET 2015
Hi
The sub program run on 172.31.9.177, the pub program run on
172.18.94.76.
If the pub doesn't pub the message for more than 2 hours, after 2 hours pub
publish
message again. But the sub can't get message anymore. I also use wireshark
to capture the packets. Pub indeed send message to sub, sub also ACK. So
the tcp link has no problem.
Meanwhile I run sub on pub's machine(172.18.94.76), after 2 hours, this
sub can still
get messages published by pub.
What happen to my sub? thanks!
[image: 内嵌图片 2]
Code is very simple:
=========Pub code ==================
void testPub(){
const char *bindAddress = "tcp://*:18001";
void *ctx = zmq_ctx_new();
assert(ctx);
void *pub = zmq_socket(ctx,ZMQ_PUB);
assert(pub);
int ret = zmq_bind( pub, bindAddress);
assert(ret == 0);
int i=0;
QString AStr = QString("A message Num %1");
QString BStr = QString("B message Num %1");
while(true){
i++;
ret = zmq_send(pub, "A" , 1, ZMQ_SNDMORE);
assert(ret>0);
ret = zmq_send(pub, AStr.arg(i).toAscii().data() , AStr.length(), 0);
assert(ret>0);
qDebug()<<AStr.arg(i);
ret = zmq_send(pub, "B" , 1, ZMQ_SNDMORE);
assert(ret>0);
ret = zmq_send(pub, BStr.arg(i).toAscii().data() , BStr.length(), 0);
assert(ret>0);
qDebug()<<BStr.arg(i);
//getchar();
Sleep(10000);
}
}
==============sub code =======================
void testSub(){
const char *bindAddress = "tcp://172.18.94.76:18001";
void *ctx = zmq_ctx_new();
assert(ctx);
void *sub = zmq_socket( ctx, ZMQ_SUB);
assert(sub);
int ret = zmq_setsockopt( sub, ZMQ_SUBSCRIBE, "A", 1);
assert( ret== 0);
ret = zmq_setsockopt( sub, ZMQ_SUBSCRIBE, "B", 1);
assert( ret== 0);
ret = zmq_connect( sub, bindAddress);
assert( ret == 0);
char buf[100];
while(true){
ret = zmq_recv( sub, buf, 99, 0);
assert(ret > 0);
buf[ret] = '\0';
qDebug()<<buf;
ret = zmq_recv( sub, buf, 99, 0);
assert(ret > 0);
buf[ret] = '\0';
qDebug()<<buf;
}
}
Regards
Jimmy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150115/2651f552/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 120112 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150115/2651f552/attachment.png>
More information about the zeromq-dev
mailing list