ZeroMQ, how to connect to external tcp socket?

Ellochka Cannibal picture Ellochka Cannibal · Jan 24, 2013 · Viewed 8.2k times · Source

Can you please tell me how you can use to send messages ZeroMQ between two programs located on different servers using some common socket? With all local sockets program works, but I do not understand how they spread to different places. Because climbs error:

Traceback (most recent call last):
  File "/Users/*****/Projects/*****/workers/internal_links_parser.py", line 20, in <module>
    socket.bind("tcp://***.***.***.***:5000")
  File "socket.pyx", line 447, in zmq.core.socket.Socket.bind (zmq/core/socket.c:4312)
zmq.core.error.ZMQError: Can't assign requested address

Explain, please, and if not difficult to give an example. Thx!

Answer

Joachim Isaksson picture Joachim Isaksson · Jan 24, 2013

From the zmq socket manual on Socket.bind;

This causes the socket to listen on a network port. Sockets on the other side of this connection will use Socket.connect(addr) to connect to this socket.

In other words, this will tell 0mq to listen to a local port for incoming connections; you should use something like socket.bind("tcp://0.0.0.0:5000") to listen to all of the machine's IP addresses on port 5000.

The other side of the connection should use Socket.connect with an URL something like socket.connect("tcp://remoteip:5000") to connect to the other side listening.

It would seem from the error message that you're trying to bind to the remote address instead of binding to the local and connecting to the remote.