I have a listener like this:
receiver r(io_service,
boost::asio::ip::address::from_string(argv[1]),
boost::asio::ip::address::from_string(argv[2]));
If I run the code with parameters
./BoostAsioMCReceiver 0.0.0.0 239.255.0.1
the listener gets all multicast packets fine from the sender (on a different computer). However, if I actually enter the ethernet IP address of the machine, for example
./BoostAsioMCReceiver 172.22.1.5 239.255.0.1
The receiver doesn't seem to get any packets. I need to do this because the computer has more than one ethernet card, and I need to be certain that packets go out a given NIC and by extension the correct switch.
Receiver looks like this:
receiver(boost::asio::io_service& io_service,
const boost::asio::ip::address& listen_address,
const boost::asio::ip::address& multicast_address)
: socket_(io_service)
{
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);
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));
}
private:
boost::asio::ip::udp::socket socket;
boost::asio::ip::udp::endpoint sender_endpoint;
Why is this happening, and what is the suggested fix?
Thanks.