如何在具有多个IP的机器上控制ZeroMQ数据包的源IP地址? [英] How to control the source IP address of a ZeroMQ packet on a machine with multiple IPs?

查看:26
本文介绍了如何在具有多个IP的机器上控制ZeroMQ数据包的源IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 标准库的socket.create_connection()method 有一个源地址选项,用于控制连接使用的源 IP.

The Python standard library's socket.create_connection()method has a source address option, for controlling which source IP a connection uses.

如果机器有多个地址,我如何用 Python ZeroMQ 套接字做同样的事情?

How do I do the same thing with a Python ZeroMQ socket, given a machine that has multiple addresses?

在这种情况下,我一直在使用 Linux 的 iproute2 ip addr add 来创建地址和 ZeroMQ PUB/SUB 套接字原型.

In this case, I've been using Linux's iproute2 ip addr add to create the addresses and the ZeroMQ PUB/SUB socket-archetypes.

推荐答案

当我尝试将 .connect() 连接到远程时,我在 协议文档,将源ip放在连接字符串中的分号之前:

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

在 Python 中,这看起来像:

In Python, this looks like:

socket = zmq.Context().socket(zmq.SUB)
socket.connect('tcp://192.168.1.17:5555;192.168.1.1:5555')

这篇关于如何在具有多个IP的机器上控制ZeroMQ数据包的源IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆