[zeromq-dev] Problem with zeromq and large messages

Brant Merryman brantm at phmgmt.com
Fri Jan 3 18:48:00 CET 2014

I have been using zeromq in my application and I’ve been having some problems with it.

Sometimes I need to send large messages. I have code that works kind of like this:

char eventBuffer[BUFFER_SIZE];

for (int more = 1; more; ) {
rc = zmq_recv(socket, eventBuffer, BUFFER_SIZE, 0);
if (rc > 0) {
<accumulate the data in the event buffer>
size_t moreSz = sizeof(int);
zmq_getsockopt(socket, ZMQ_RCVMORE, &more, &moreSz);
} else {
printf(“zmq_recv failed: %d\n”, rc);
more = 0;

<handle the accumulated data>

The process that is sending the data uses code like this:

rc = zmq_send(socket, data, data_length, 0);
if (rc <= 0) {
printf(“zmq_send failed: %d\n”, rc);

The problem is that when the data being sent is less than BUFFER_SIZE – no problem. But when the data sent is larger than BUFFER_SIZE, the zmq_recv call gets the same number of bytes that was sent. What I was expecting was that the number of bytes returned would be BUFFERSIZE and that zmq_getsockopt would result in more being 1 and we would repeat that data_length/BUFFER_SIZE times and then once more for the remaining data and then more would go to 0 and we would exit the loop.

How the heck is this supposed to work? What am I doing wrong?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140103/76ac83e4/attachment.htm>

More information about the zeromq-dev mailing list