向同一网络上的所有其他应用程序实例发送消息

Sending a message to all other instances of the application on the same network

如何在同一网络上使用多播发送消息?

我正在使用 C++,带有库提升。我玩过发送者和接收者的例子。

但我也有几个问题,我是网络和 C++ 的新手。 多播端口设置为 30001,有什么好的理由吗?

示例建议我使用,对于发件人:

IPv4 239.255.0.1

IPV6 ff31::8000:1234

对于接收者:

IPv4 0.0.0.0 239.255.0.1

IPv6 0::0 ff31::8000:1234

为什么是这些特定地址?

同样在接收者示例中,有一个部分专门用于加入多播地址,有没有办法检查这个地址上是否出现了新连接?查看哪些新实例加入或离开连接,这可能吗?

但我的主要问题是,如果我从我的计算机 运行 示例中发送像 Hello World 这样的消息,它会显示在同一网络上的另一台计算机上吗?

Why those specific addresses ?

这些是 IP 协议 (IPv4/IPv6) 为多播指定的地址。部分地址是组规范(我认为 IPv4 为 255.0.1,IPv6 为 1234)。流量被转发到本地计算机上的特定端口,但我没有know/can找不到详细信息。

Also in the receiver example, there is a section dedicated to joining the multicast address, is there a way to check if a new connection has showed up on this address ? to see what new instance joins or leaves the connection, is this possible ?

不,没有这样的内置功能。多播应该被发送到至少所有感兴趣的机器。加入是向 network/local OS 发出的信号,表明您是一台感兴趣的机器,它应该接收并转发相关数据包。在所有情况下都不需要转发此类信号(即如果路由器已经有数据包)。

然而,您可以在加入后在频道上广播您的状态,但这是您要在多播之上实施的协议的一部分。

But my main question is, if I were to send a message like Hello World from my computer running the example, would this show up on another computer on the same network ?

视情况而定。如果您连接到相同的第 1 层(直接以太网或直接 WiFi)结构,那么可能是。如果您必须跳过 router/access 点,他们可能有禁止流量的防火墙规则。

标准见wikipedia for a summary of how it works. Or read the rfc1112, rfc4604 and rfc5771