I think you have to set socket options before connecting instead of after.
On Nov 9, 2013 7:30 PM, "Gerhard Martin" <[email protected]> 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
> [email protected]
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev