Search code examples
c#pythonproxyzeromqnetmq

Sending message with Router-Dealer Proxy using c# and python


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 Router-Dealer Proxy with python.

I tried running the proxy python script first, then running c# (client), then python (server). However, when I run the python (server), it gives me an "Address in use" error message.

Am I running them in a wrong order OR is there something wrong with the proxy python script (shown below)?

5602 = c# client

5603 = python server

def main():

context = zmq.Context()

# Socket facing clients
frontend = context.socket(zmq.ROUTER)
frontend.bind("tcp://*:5602")

# Socket facing services
backend  = context.socket(zmq.DEALER)
backend.bind("tcp://*:5603")

zmq.proxy(frontend, backend)

# We never get here…
frontend.close()
backend.close()
context.term()

if __name__ == "__main__":
main()

Solution

  • I'm assuming your servers use bind, so the proxy should connect to them rather than also using bind.

    Note: in zeromq the order of application startup doesn't matter so you can tell your proxy to connect to a server that doesn't yet exist, when the server is started the connection will be made.