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 <http://zguide.zeromq.org/page:all#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 <http://zguide.zeromq.org/php:chapter3#The-DEALER-to-ROUTER-Combination> 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; client.connect(endpoint); 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) frontend.bind("tcp://*:5559") # 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() print(message) frontend.send_multipart(message) 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; peer2.connect(endpoint); //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 messages. Bernardo Augusto García Loaiza Ingeniero de Sistemas Estudiante de Maestría en Ingeniería Informática - Universidad EAFIT http://about.me/bgarcial
_______________________________________________ zeromq-dev mailing list zeromq-dev@lists.zeromq.org https://lists.zeromq.org/mailman/listinfo/zeromq-dev