开发者

How to Receive from Multiple Multicast Remote Interfaces?

I am using Boost::asio for the following.

I am trying to receive packets from multiple udp multicast channels. However, I am having great trouble in trying to get this to work. At the moment, I can only listen to the first channel.

The following is my code:

// create a list of endpoints for each channel

endpoint_list.push_back(new boost::asio::ip::udp::endpoint( (boost::asio::ip::address::from_string(boost::get<1>(interfaces_list[i]))).to_v4(), boost::get<2>(interfaces_list[i])));

// create a list of join_groups for each channel

join_group_list.push_back(new boost::asio::ip::multicast::join_group( (boost::asio::ip::address::from_string(boost::get<1>(interfaces_list[i]))).to_v4(),   (boost::asio::ip::address::from_string(boost::get<0>(interfaces_list[i]))).to_v4() ) );

//initiate options on each channel

socket_list[i]->open(endpoint_list[i]->protocol());     socket_list[i]->set_option(boost::asio::ip::udp::socket::reuse_address(true));
socket_list[i]->bind(*endpoint_list[i]);
socket_list[i]->set_option(*join_group_list[i]);

// callback on each socket

socket_list[i]->async_receive_from(boost::asio::buffer(buffer_array_list[i], max_length), sender_endpoint_, boost::bind(&PacketLogger::HandleReceiveFrom, this, i, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));

As you can see, each channel has their own sockets and such. I have 3 pieces of information: local interface/remote interface/remote port, all of which are correct because I can listen perfectly fine on the first channel.

Does a开发者_运维问答nyone have any ideas on what could be wrong?

Thank.


IP multicast is managed at the host level not the socket level, if you have two socket subscriptions that are conflicting then something is going to break.

For example you can join a group in send-only mode via the IP_MULTICAST_IF option, subsequently no application on that machine can subscribe to any data on that group.

To proceed try the subscriptions in a third party application or may some basic C code instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜