I think there is an error in the sample code example for udp multicast .
In the code example, they bind the socket to the local interface, but for udp multicast, you must bind to the IP and port of the udp multicast group.
socket_.bind(listen_endpoint);
it should be:
socket_.bind( boost::asio::ip::udp::endpoint( multicast_address, multicast_port ) );
see multicast :
... for the process of receiving multicast datagrams, he must ask the kernel to join the group and bind the port where the datagrams are sent to. The UDP level uses both the destination address and the port to demultiplex packets and decide which socket to deliver them to ...
... you need to tell the kernel which multicast groups we are interested in. That is, we must ask the kernel to "join" those multicast groups ...
check if you joined the group on the correct interface with netstat -g | grep <multicast_group_ip> netstat -g | grep <multicast_group_ip>
I believe the incorrect boost example code is:
boost::asio::ip::udp::endpoint listen_endpoint( listen_address, multicast_port); socket_.open(listen_endpoint.protocol()); socket_.set_option(boost::asio::ip::udp::socket::reuse_address(true)); socket_.bind(listen_endpoint); // Join the multicast group. socket_.set_option( boost::asio::ip::multicast::join_group(multicast_address)); socket_.async_receive_from( boost::asio::buffer(data_, max_length), sender_endpoint_, boost::bind(&receiver::handle_receive_from, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
stefanB
source share