[zeromq-dev] How to set filter for struct type

liuchuanbo at gmail.com liuchuanbo at gmail.com
Thu Aug 8 16:30:54 CEST 2013


Hi, everyone

On PUB side: wd is struct type message and I send it to the subscriber.
typedef struct tag_StructData
{
	string name;
}StructData;

StructData wd;
//  Prepare our context and publisher
zmq::context_t context (1);
zmq::socket_t publisher (context, ZMQ_PUB);
int msgSize = sizeof(wd);
zmq::message_t message(msgSize);
memcpy ((void *) message.data(), &wd, msgSize);
publisher.send(message);


On SUB side:
// Receive Everything
	subscriber.setsockopt(ZMQ_SUBSCRIBE, NULL, 0); 
// How to set a filter to receive the struct message with the specified name, for example "ABC".
 
	//string msg;
	StructData *msg;
	while(true){
		zmq::message_t m;
		subscriber.recv(&m);
		msg = (StructData *)m.data();
		cout << msg->Symbol << endl;
	}


Thanks.

--
Best Regards,
Roy Liu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130808/4156eec6/attachment.htm>


More information about the zeromq-dev mailing list