[zeromq-dev] why not receive message in subscriber

Gerhard Martin galeomaga at gmail.com
Fri Nov 8 10:10:53 CET 2013


why not receive message in subscriber

void task2(int testparam)
{
    printf("task 2 %d\n", testparam); 
    
    zmq::context_t context(1);  
    zmq::socket_t subscriber(context, ZMQ_SUB); 
    printf("before connect\n"); 
    subscriber.connect("tcp://127.0.0.1:5556");  
    printf("after connect\n"); 
    const char *filter = "";  
    subscriber.setsockopt(ZMQ_SUBSCRIBE, filter, strlen(filter));  
    zmq::message_t update;  
    //subscriber.recv(&update); 
    //printf("end recv %s", update.data());
    while(true){ 
        //try
        //{    
            printf("server begin recv\n");
            subscriber.recv(&update); 
            printf("succeed to receive\n");
            printf("server end recv %s\n", 
static_cast<char*>(update.data()));
            //printf("%s is sent\n", (void *)reply.data());
        //}catch(...)
        //{
            //printf("Sub Receiver Error ");
        //}
    }
}

main(){
...
zmq::context_t context(1);  
    zmq::socket_t publisher (context, ZMQ_PUB);  
    printf("before bind\n");
    publisher.bind("tcp://*:5556");  
    printf("after bind\n");
    zmq::message_t reply(12);
    memcpy ((void *) reply.data(), "Martin", 6);
    printf("%s is sent\n", (void *)reply.data());
    printf("before send\n");
    for(int k=0; k<10; ++k)
    {
        publisher.send(reply); 
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20131108/6ef1dc05/attachment.html>


More information about the zeromq-dev mailing list