Now it’s really easy to throw data around using the 0MQ helpers written up before!
Subscribe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void SubscribeCallback(uint8_t *buf, int size) | |
| { | |
| //do whatever with the payload received | |
| } | |
| //set up the subscribe thread | |
| SubscribeZeroMQDataThreadArgs *subscribeThread = StartSubscribe(zmqContext, "tcp://hostname:port", "topic", SubscribeCallback, "LogCategory"); | |
| //shutdown the subscribe thread later | |
| StopSubscribe(subscribeThread); |
Request Reply
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static RequestReplyZeroMQReply* RequestReplyCallback(const char *request, const void *argument, const uint8_t *data, const int size) | |
| { | |
| RequestReplyZeroMQReply *reply = malloc(sizeof(RequestReplyZeroMQReply)); | |
| someData_t *someData; | |
| int len = get_some_data_to_return(&someData, data, size); | |
| reply->data = someData; | |
| reply->size = len; | |
| return reply; | |
| } | |
| //set up the request reply thread | |
| //NULL could be a pointer to a variable you'd like passed to the callback | |
| RequestReplyZeroMQThreadArgs* thread = StartRequestReply(zmqContext, "tcp://hostname:port", RequestReplyCallback, NULL, "logCategory"); | |
| StopRequestReply(thread); |
Forwarding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ForwardZeroMQDataThreadArgs *forwardThread = StartForward(context, "tcp://forwardTransport", "logCategory", 2, "ipc://someSubTransport", "tcp://anotherSubTransport"); | |
| StopForward(forwardThread); |
Leave a comment