简体   繁体   中英

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
  • Process B tries joining 224.1.1.101 port 10000

Process A is getting data from 224.1.1.100:10000 just fine.

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)

The underlying code of the 2 processes is using 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).

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

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:


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. By switching the listenInterface that is used on the bind to the local end point, I got it to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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