[zeromq-dev] ZMQ DEALER - ROUTER Communication

Bernardo Augusto García Loaiza botibagl at gmail.com
Thu Mar 15 00:17:17 CET 2018

I am currently working on a project that requires some communication over
the network of a different data types from some entities of a distributed
system and I am using ZMQ.

The main goal of the project is to have a central node which services
clients which can connect at any time. For each client connected, the
central node should manage the message communication between the two.
Currently, and by the moment, all communication is happening over TCP.

The clients need to send and receive messages at any time so they are
*ZMQ_DEALER* type sockets and the central node is *ZMQ_ROUTER*

I have been reading, about of the different patterns communication and I
think the Asynchronous Client/Server pattern
is suited because I am interested in having several clients talking to each
other in a collaborative way, having maybe a server broker or middleware,
which be useful to receive and forward messages between entities related
and because basically, the DEALER - TO - ROUTER
combination is that I need.

I have a ZMQ_DEALER socket client which connect to ZMQ_ROUTER socket server

#include <zmq.hpp>#include "zhelpers.hpp"using namespace std;
int main(int argc, char *argv[]){

    zmq::context_t context(1);
    zmq::socket_t client(context, ZMQ_DEALER);

    const string endpoint = "tcp://localhost:5559";

    client.setsockopt(ZMQ_IDENTITY, "PEER1", 5);
    cout << "Connecting to ZMQ Network Manager " << endpoint << "..." << endl;
    for (int request = 0; request < 10; request++)

        s_sendmore(client, "");
        s_send(client, "Testing sending some data");

        std::string string = s_recv(client);

        std::cout << "Received reply " << request
                  << " [" << string << "]" << std::endl;

On my server code, I have a ZMQ_ROUTER which receive and manage the
messages is, making bind it to a well port. This server is made in Python

import zmq
context = zmq.Context()
frontend = context.socket(zmq.ROUTER)
# Initialize a poll set
poller = zmq.Poller()
poller.register(frontend, zmq.POLLIN)
print("Creating Server Network Manager Router")
while True:
    socks = dict(poller.poll())

    if socks.get(frontend) == zmq.POLLIN:
        message = frontend.recv_multipart()

On my other peer/client I have the following:

#include <zmq.hpp>#include "zhelpers.hpp"using namespace std;
int main (int argc, char *argv[]){

    zmq::context_t context(1);
    zmq::socket_t peer2(context, ZMQ_DEALER);

    const string endpoint = "tcp://localhost:5559";

    peer2.setsockopt(ZMQ_IDENTITY, "PEER2", 5);
    cout << "Connecting to ZMQ Network Manager " << endpoint << "..." << endl;
    //s_sendmore(peer2, "");
    //s_send(peer2, "Probando");

    //std::string string = s_recv(peer2);

    //std::cout << "Received reply " << " [" << string << "]" << std::endl;

    for (int request = 0; request < 10; request++)

        s_sendmore(peer2, "");
        s_send(peer2, "Probando");

        std::string string = s_recv(peer2);

        std::cout << "Received reply " << request
                  << " [" << string << "]" << std::endl;

But each that I execute some client, their respective messages do not
arrive at another peer client. The messages arrive at ZMQ_ROUTER, but I
haven't clear on my server code how to should I forward this messages to
the respective clients.

I think so (may be obvious) that in my server code, I am not sending

Bernardo Augusto García Loaiza
Ingeniero de Sistemas
Estudiante de Maestría en Ingeniería Informática - Universidad EAFIT
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20180314/f96d4f7e/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 6585 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20180314/f96d4f7e/attachment.png>

More information about the zeromq-dev mailing list