使用boost::asio在同一主机上发送多播消息
Multicast message on same host using boost::asio
我正在实现发送方/接收方应用程序,以便在同一主机上进行多播对话。
在构造函数中,我使用以下代码来设置套接字。
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));
其中listenAddr为0.0.0.0。
我的发送方法代码如下:
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));
其中m_remoteEndpoint为组播地址224.0.1.129和组播端口320。
应用程序A似乎没有从应用程序B接收多播消息,反之亦然,当两者都在同一主机上时。但是如果我将应用程序B移动到同一子网上的另一台机器上……然后,应用程序A听到多播消息并回复给应用程序B,应用程序B也可以接收到应用程序A的回复消息。我启用了环回,并设置了套接字reuse_address选项。我错过了什么?
当您删除环回选项时会发生什么。我有一个类似的问题,并删除修复它。
相关文章:
- 如何使用虚幻引擎"filter"多播?
- 为什么 zmq 将多条消息打包到一个 TCP 帧中?
- 无法在 Windows 10 上加入 IPV6 多播组
- TCP 缓冲区中的多条消息
- 如何在 Linux 上的 C/C++ 中使用 ipv6 udp 套接字进行多播?
- IPv6 多播在局域网中不起作用
- 简单的多播应用程序无法在同一网络上的不同计算机上运行
- Linux VS Windows 上的 UDP 多播差异
- 在覆盆子Pi路由器上进行多播
- C 在特定接口上接收多播
- C++ protobuf:如何通过"SerializeToOstream()"将多条消息写入文件
- 为什么Zeromq PGM多播未接收多播消息?(C ,Windows)
- Ubuntu C 多播双休假组消息
- 如何从已经订阅的组中接收多播数据包
- 我是否需要2个插座来进行多播和单播
- 使用 Boost ASIO 在 macOS 上到特定接口的多播
- Windows 2008 R2中缺少多播消息
- 使用boost::asio在同一主机上发送多播消息
- Erlang-向UDP多播会话发送消息
- 如何在C窗口中向一对对等体发送多播消息