简体   繁体   English

在同一端口上绑定两个多播套接字

[英]Binding two multicast sockets on the same port

I'm trying to join two different multicast groups from two different processes on the same machine: 我正在尝试从同一台计算机上的两个不同进程中加入两个不同的多播组:

  • Process A joins 224.1.1.100 port 10000 进程A加入224.1.1.100端口10000
  • Process B tries joining 224.1.1.101 port 10000 进程B尝试加入224.1.1.101端口10000

Process A is getting data from 224.1.1.100:10000 just fine. 进程A从224.1.1.100:10000获取数据就好了。

The problem is that process B is not receiving traffic from 224.1.1.101:10000 -- its instead receiving traffic from the join that process A did (224.1.1.100:10000) 问题是进程B没有从224.1.1.101:10000接收流量-而是从进程A的联接接收流量(224.1.1.100:10000)

The underlying code of the 2 processes is using Boost Asio. 这两个进程的基础代码使用的是Boost Asio。 Each process is opening the socket to the same port 10000. However, each one is sending a join to a separate multicast group (process A to 224.1.1.100, process B to 224.1.1.101). 每个进程都将套接字打开到同一端口10000。但是,每个进程都将联接发送到单独的多播组(进程A至224.1.1.100,进程B至224.1.1.101)。

The key problem seems to be the two processes opening the socket to the same port. 关键问题似乎是两个进程将套接字打开到同一端口。 How can I have this work in light of having to listen to the same port on the two multicast groups (224.1.1.100 and 224.1.1.101)? 鉴于必须侦听两个多播组(224.1.1.100和224.1.1.101)上的相同端口,我该如何进行这项工作?

Process A example code: 流程示例代码:


listenInterface( boost::asio::ip::address::from_string( "0.0.0.0" ) ),
localEndpoint = boost::asio::ip::udp::endpoint( listenInterface, 10000 );
socket.bind( localEndpoint );
socket.set_option( boost::asio::ip::multicast::join_group( boost::asio::ip::address::from_string( "224.1.1.100" ) ) );

Process B example code: 流程B示例代码:


listenInterface( boost::asio::ip::address::from_string( "0.0.0.0" ) ),
localEndpoint = boost::asio::ip::udp::endpoint( listenInterface, 10000 );
socket.bind( localEndpoint );
socket.set_option( boost::asio::ip::multicast::join_group( boost::asio::ip::address::from_string( "224.1.1.101" ) ) );

I figured it out. 我想到了。 The root cause was not usin a unique listenInterface between the two processes. 根本原因不是在两个进程之间使用唯一的listenInterface。 By switching the listenInterface that is used on the bind to the local end point, I got it to work. 通过将绑定上使用的listenInterface切换到本地端点,我可以使它工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM