Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:36:04+00:00 2026-06-18T09:36:04+00:00

Code Connected Volume 1 – page 47 have an example about how to receive

  • 0

Code Connected Volume 1 – page 47 have an example about how to receive multipart message:

while (1) {
    zmq_msg_t message;
    zmq_msg_init(&message);
    zmq_msg_recv(&message, socket, 0);
    // Process the message frame
    ...
    zmq_msg_close(&message);
    if (!zmq_msg_more(&message))
        break;
}

Is this correct? Shouldn’t we use zmq_msg_close() after zmq_msg_more()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:36:05+00:00Added an answer on June 18, 2026 at 9:36 am

    The API reference for zmq_msg_more() and zmq_msg_recv() (ZeroMQ 3.2.2 Stable) both contain examples showing that zmq_msg_close() is called after zmq_msg_more. As far as I know the API docs do not specifically state anything to contradict this, thus the example from Code Connected seems wrong. The documentation for zmq_msg_close() states that the actual memory release may be postponed by underlaying layers, implicating that the zmq_msg_more() operation may succeed but it still looks wrong to call it after closing the message.

    Example from zmq_msg_more() API documentation (3.2.2) (edited slightly for readability):

    zmq_msg_t part;
    while (true) 
    {
        //  Create an empty ØMQ message to hold the message part
        int rc = zmq_msg_init (&part);
        assert (rc == 0);
    
        //  Block until a message is available to be received from socket
        rc = zmq_recvmsg (socket, &part, 0);
        assert (rc != -1);
    
        if (zmq_msg_more (&part))
            fprintf (stderr, "more\n");
        else 
        {
            fprintf (stderr, "end\n");
            break;
        }
        zmq_msg_close (part); 
    }
    

    However, looking in the ZeroMq Guide regarding Multi-Part Messages, that example actually checks for more messages after closing the message, but that is achieved by checking the socket using zmq_getsockopt(), without using any references to the message. I suspect the Code Connected examples simply used that example and changed from zmq_getsockopt() to zmq_msg_more() (probably incorrecly so).

    Example from ZeroMq Guide (multi-part messages):

    while (1) 
    {
        zmq_msg_t message;
        zmq_msg_init (&message);
        zmq_msg_recv (&message, socket, 0);
        //  Process the message frame
        zmq_msg_close (&message);
        int more;
        size_t more_size = sizeof (more);
        zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
        if (!more)
            break;      //  Last message frame
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Code Connected book volume 1(page 23) there is a example for using PUSH
Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
I have a bluetooth bar code scanner connected to my tablet. Whenever i scan
I have managed to get the connected clients IP with the code below but
i have write a java code and am connected to a bluetooth device from
I have code in my application that detects if Wi-Fi is actively connected. That
The below code is connected to a contact form. On submit, you receive one
I have in the fact copied the code of Login page in the ASP.NET
I have the following code that if not connected to the internet hits the
I have a code base web application that is connected to 2 databases. Depending

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.