0

I am able to have c# (client) and python (server) talk to each other by using a simple request-reply. However, I want my web application built on c# asp.net to be stable and need more clients and servers, so I tried connecting c# and python using the Extended REQ-REP connection.

But when I run the code below, it does not do its job as a broker and outputs nothing. What am I doing wrong here?

5600 = c# client

5601 = python server

using (var frontend = new RouterSocket("@tcp://127.0.0.1:5600"))
                        using (var backend = new DealerSocket("@tcp://127.0.0.1:5601"))
                        {
                            // Handler for messages coming in to the frontend
                            frontend.ReceiveReady += (s, p) =>
                            {
                                var msg = p.Socket.ReceiveFrameString();
                                backend.SendFrame(msg); // Relay this message to the backend
                            };

                            // Handler for messages coming in to the backend
                            backend.ReceiveReady += (s, p) =>
                            {
                                var msg = p.Socket.ReceiveFrameString();
                                frontend.SendFrame(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();
                            }
                        }
Oleole
  • 381
  • 4
  • 21

1 Answers1

0

You are not sending the all message frames with the correct flags.

You can try and user Proxy of netmq that does exactly that. If you still want to write it by hand take a look how the proxy do it with the correct frames flags here:

https://github.com/zeromq/netmq/blob/master/src/NetMQ/Proxy.cs

Update:

Following is an example on how to use the proxy in your case:

using (var frontend = new RouterSocket("@tcp://127.0.0.1:5600"))
using (var backend = new DealerSocket("@tcp://127.0.0.1:5601"))
{
    using (var poller = new NetMQPoller { backend, frontend })
    {
        var proxy = new Proxy(frontend, backend, null, poller);
        proxy.Start();
        proxy.Run();
    }
}

You can also use it without a poller:

using (var frontend = new RouterSocket("@tcp://127.0.0.1:5600"))
using (var backend = new DealerSocket("@tcp://127.0.0.1:5601"))
{       
    var proxy = new Proxy(frontend, backend);
    proxy.Start();        
}
somdoron
  • 4,653
  • 2
  • 16
  • 24
  • In the link you shared, it seems like I can simply "add" the proxy of netmq after the Routher-Dealer capture socket as there is no place in the code specifying the front and back end port. – Oleole Aug 17 '16 at 17:29
  • I'm not sure I understand your comment, anyway I added a code example, is that helps? – somdoron Aug 18 '16 at 09:14
  • I decided to run proxy on python instead. Thanks so much for your help though :) – Oleole Aug 19 '16 at 14:28