How to control the source IP address of a ZeroMQ packet on a machine with multiple IPs?

前端 未结 2 1336
情话喂你
情话喂你 2020-11-21 07:12

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 sam

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-21 08:08

    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')
    

提交回复
热议问题