The Python standard library's socket
.create_connection()
method has a source address option, for controlling which source IP a connection uses.
How do I do the same thing with a Python ZeroMQ socket, given a machine that has multiple addresses?
In this case, I've been using Linux's iproute2 ip addr add
to create the addresses and the ZeroMQ PUB/SUB
socket-archetypes.
When trying to .connect()
to a remote, I found the answer in the protocol documentation, put the source ip before a semicolon in the connect string:
rc = zmq_connect(socket, "tcp://192.168.1.17:5555;192.168.1.1:5555")
In Python, this looks like:
socket = zmq.Context().socket(zmq.SUB)
socket.connect('tcp://192.168.1.17:5555;192.168.1.1:5555')