I'm implementing sender/receiver applications to talk multicast on the same host.
In my constructor, I have the following code to setup the socket.
boost::asio::ip::udp::endpoint listenEndpoint(listenAddr, mcastPort);
m_socket.open(listenEndpoint.protocol());
m_socket.set_option(boost::asio::ip::udp::socket::reuse_address(true));
m_socket.set_option(boost::asio::ip::multicast::enable_loopback(true));
m_socket.set_option(boost::asio::ip::multicast::hops(1));
m_socket.bind(listenEndpoint);
// Join the multicast group
m_socket.set_option(boost::asio::ip::multicast::join_group(mcastAddr));
m_socket.async_receive_from(boost::asio::buffer(m_data, MAX_PTP_MSG_LENGTH),
m_senderEndpoint, boost::bind(&PtpIpc::HandleReceiveFrom, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
Where listenAddr is 0.0.0.0.
My sending method code is as follows:
m_socket.async_send_to(boost::asio::buffer(data, size), m_remoteEndpoint,
boost::bind(&PtpIpc::HandleSendTo, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
Where m_remoteEndpoint is multicast address 224.0.1.129 and muticast port 320.
Application A doesn't seem to receive multicast messages from Application B and vice versa when both are on the same host. But if I move Application B to another machine on the same subnet... then Application A hears multicast message and reply back to Application B, which can also receive the reply message from Application A. I've enabled loopback and also set the socket reuse_address option. What am I missing?