title: NetMQ client to client messaging
body: <p>I'm trying to create an rpc program to communicate hosts located on different networks and chose Router-Dealer configuration of NetMQ provided here: <a href="http://netmq.readthedocs.io/en/latest/router-dealer/" rel="nofollow">http://netmq.readthedocs.io/en/latest/router-dealer/#router-dealer</a></p>
  
  <p>But the problem is that router always selects a random dealer when routing a message to backend.
  Code which I used :</p>
  
  <pre><code>using (var frontend = new RouterSocket(string.Format("@tcp://{0}:{1}", "127.0.0.1", "5556")))//"@tcp://10.0.2.218:5559"
                  using (var backend = new DealerSocket(string.Format("@tcp://{0}:{1}", "127.0.0.1", "5557")))//"@tcp://10.0.2.218:5560"
                  {
                      // Handler for messages coming in to the frontend
                      frontend.ReceiveReady += (s, e) =&gt;
                      {
                          Console.WriteLine("message arrived on frontEnd");                            
                          NetMQMessage msg = e.Socket.ReceiveMultipartMessage();
                          string clientAddress = msg[0].ConvertToString();                            
                          Console.WriteLine("Sending to :" + clientAddress);
                          //TODO: Make routing here
                          backend.SendMultipartMessage(msg); // Relay this message to the backend                        };
  
                      // Handler for messages coming in to the backend
                      backend.ReceiveReady += (s, e) =&gt;
                      {
                          Console.WriteLine("message arrived on backend");
                          var msg = e.Socket.ReceiveMultipartMessage();
  
                          frontend.SendMultipartMessage(msg); // Relay this message to the frontend
                      };
  
                      using (var poller = new NetMQPoller { backend, frontend })
                      {
                          // Listen out for events on both sockets and raise events when messages come in
                          poller.Run();
                      }
                  }
  </code></pre>
  
  <p>Code for Client:</p>
  
  <pre><code>using (var client = new RequestSocket("&gt;tcp://" + "127.0.0.1" + ":5556"))
          {
              var messageBytes = UTF8Encoding.UTF8.GetBytes("Hello");
              var messageToServer = new NetMQMessage();
              //messageToServer.AppendEmptyFrame();
              messageToServer.Append("Server2");
              messageToServer.Append(messageBytes);
              WriteToConsoleVoid("======================================");
              WriteToConsoleVoid(" OUTGOING MESSAGE TO SERVER ");
              WriteToConsoleVoid("======================================");
              //PrintFrames("Client Sending", messageToServer);
              client.SendMultipartMessage(messageToServer);
  
              NetMQMessage serverMessage = client.ReceiveMultipartMessage();
              WriteToConsoleVoid("======================================");
              WriteToConsoleVoid(" INCOMING MESSAGE FROM SERVER");
              WriteToConsoleVoid("======================================");
              //PrintFrames("Server receiving", clientMessage);
              byte[] rpcByteArray = null;
              if (serverMessage.FrameCount == 3)
              {
                  var clientAddress = serverMessage[0];
                  rpcByteArray = serverMessage[2].ToByteArray();
              }
  
              WriteToConsoleVoid("======================================");
              Console.ReadLine();
          }
  </code></pre>
  
  <p>Code for Dealer:</p>
  
  <pre><code>using (var server = new ResponseSocket())
          {
              server.Options.Identity = UTF8Encoding.UTF8.GetBytes(confItem.ResponseServerID);
              Console.WriteLine("Server ID:" + confItem.ResponseServerID);
              server.Connect(string.Format("tcp://{0}:{1}", "127.0.0.1", "5557"));
              using (var poller = new NetMQPoller { server })
              {
                  server.ReceiveReady += (s, a) =&gt;
                      {
                          byte[] response = null;
                          NetMQMessage serverMessage = null;
                          try
                          {
                              serverMessage = a.Socket.ReceiveMultipartMessage();
                          }
                          catch (Exception ex)
                          {
                              Console.WriteLine("Exception on ReceiveMultipartMessage : " + ex.ToString());
                              //continue;
                          }
                          byte[] eaBody = null;
                          string clientAddress = "";
                          if (serverMessage.FrameCount == 2)
                          {
                              clientAddress = serverMessage[0].ConvertToString();
                              Console.WriteLine("ClientAddress:" + clientAddress);
                              eaBody = serverMessage[1].ToByteArray();
                              Console.WriteLine("Received message from remote computer: {0} bytes , CurrentID : {1}", eaBody.Length, confItem.ResponseServerID);
                          }
                          else
                          {
                              Console.WriteLine("Received message from remote computer: CurrentID : {0}", confItem.ResponseServerID);
                          }
                      };
                  poller.Run();
              }
          }
  </code></pre>
  
  <p>Is it possible to choose a specific backend on frontend.ReceiveReady?
  Thanks!</p>