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

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

问题描述

Python标准库的 socket .create_connection() 方法具有源地址"选项,用于控制连接使用的源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() 到远程服务器时,我在

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天全站免登陆