[zeromq-dev] why not receive message in subscriber

shancat shannenlaptop at gmail.com
Sat Nov 9 09:40:58 CET 2013


I think you have to set socket options before connecting instead of after.
On Nov 9, 2013 7:30 PM, "Gerhard Martin" <galeomaga at gmail.com> wrote:

> 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);
>     }
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20131109/c6bd0ac1/attachment.html>


More information about the zeromq-dev mailing list