Networking Reference
In-Depth Information
Working with multi-part messages
We always define messages using zmq_msg . When we want to send multi-part
messages, again, we need to use zmq_msg . For example, if the data package is divided
into 10 parts, you need to create 10 zmq_msg sockets. The client either receives all the
message parts or nothing at all. In order to send multi-part messages, the ZMQ_SNDMORE
lag must be set during the zmq_send call.
int zmq_send(void* socket, void* buf, size_t len, int flags);
The following is the request-reply example that we used in Chapter 1 , Getting Started ,
but this time we will send the message in multiple parts. First, let's have a look at the
server code:
Request - Reply
Send "world" in multiple-parts.
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include "zmq.h"
int main (int argc, char const *argv[]) {
void* context = zmq_ctx_new();
void* respond = zmq_socket(context, ZMQ_REP);
zmq_bind(respond, "tcp://*:4040");
for(;;) {
zmq_msg_t request;
zmq_msg_recv(&request, respond, 0);
Search MirCeyron ::

Custom Search