The DEALER to REP Combination

Now, let’s replace the REQ client with a DEALER. This gives us an asynchronous client that can talk to multiple REP servers. If we rewrote our “Hello World” client using DEALER, we’d be able to send off any number of “Hello” requests without waiting for replies.

When we use a DEALER to talk to a REP socket, we must accurately emulate the envelope that the REQ socket would have sent, or the REP socket will discard the message as invalid. So, to send a message, we:

  1. Send an empty message frame with the MORE flag set.

  2. Send the message body.

And when we receive a message, we:

  1. Receive the first frame and, if it’s not empty, discard the whole message.

  2. Receive the next frame and pass that to the application.

Get ZeroMQ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.