[zeromq-dev] Looking for the best server/client layout

Goswin von Brederlow goswin-v-b at web.de
Tue Jul 29 12:22:39 CEST 2014

On Thu, Jul 24, 2014 at 02:44:31PM -0400, Greg Ward wrote:
> On 24 July 2014, Mike Zupan said:
> > I'm new to zeromq on the dev side and looking for the best layout to use
> > for a server/client setup where the server can send commands to clients and
> > also the clients can send data back to the server without being told to run
> > a command. Pretty much like the client checking in with some data it found
> > on the server as it happens instead of waiting for the server to say ok run
> > this command give me data back.
> I believe you need a DEALER/ROUTER pair. REQ/REP is limited in that
> it's a strict back-and-forth communication pattern: 1 request, 1
> reply, 1 request, ad infinitum. So REQ/REP is not terribly useful in
> real-world apps like yours.
> DEALER/ROUTER is the real-world version of REQ/REP -- either peer can
> send a message at any time.
> IIUC, the typical usage is DEALER for the client connected to ROUTER
> on the server.
>        Greg


Both kinds allow multiple peers to connect but a DEALER socket will
send outgoing messages in a round-robin fashion to some peer, which
peer you have no control over. Similary incoming messages have no
origin attached to them so you don't know where they came from.

On the other hand a ROUTER socket will prepend the peer identity to
every incoming message and use the first frame of every outgoing
message as the peer identity the message should got to. So you get
told from where a message came and can tell it where to send messages.

Most often you have a star shaped topology. A single server will have
many clients and clients only have one server. So you tend to have
ROUTER on the server and DEALER on client side.

On the other hand if a server has many workers and doesn't care which
worker gets each request a DEALER/DELAER setup works just fine.


More information about the zeromq-dev mailing list