c++ - UDP 多播不适用于 linux Debian

标签 c++ linux boost udp multicast

嗨,我的 c++ 代码或 Linux Debian 环境中存在 UDP 多播问题。
我正在使用 boost 1.67。
注:我在 Windows 和 Linux 中都使用我的代码。但在 Linux 中它不起作用,但在 Windows 中它起作用。
我可以在 Debian 中看到带有 netcat 的多播包,所以多播流就在那里!网卡上启用了多播。
所以我相信我的代码有效,但不适用于 Linux ......这可能是一个 boost 问题吗?
我的传入流量接口(interface)具有 IP 192.168.0.1,我使用的多播地址是 239.16.33.1,端口为 20001。

---Initialize_Source
...
    Socket->async_receive(
        boost::asio::buffer(Read_Buffer, MAX_LENGTH),
        boost::bind(&Udp_Transport::Handle_Receive_From, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)
        );
...
    
---Join_Multicast_Group  
    // allow other to be bound to the same address.
    Socket->set_option(boost::asio::ip::udp::socket::reuse_address(true));
    // Join the multi cast group.
    Socket->set_option(boost::asio::ip::multicast::join_group(Multicast_Address));
    Socket->set_option(boost::asio::ip::multicast::hops(64));
这里没有太多可能出错的地方,但任何提示都会对我有很大帮助!
/H

最佳答案

实际上我发现如果我将多播端口绑定(bind)到网卡 IP 192.168.0.1 那么它只能在 Windows 中工作。但是,如果我将多播端口绑定(bind)到 IP 0.0.0.0,它也可以在 Linux 中使用。
然后我刚刚加入了这个小组:
套接字->set_option(boost::asio::ip::multicast::join_group(Multicast_Address));

关于c++ - UDP 多播不适用于 linux Debian,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65074080/

相关文章:

c++ - 如何在一台 Ubuntu 机器上安装 2 个 Opencv 版本以及如何一次激活一个版本进行编译?

Java运行时exec()不解析环境变量

c++ - Turtle(模拟框架)编译错误

c++ - boost::asio -- asio_handler_deallocate 在 io_service::~io_service() 中调用,在 io_service::stop() 之后

c++ - QT read Ready()TCP套接字在需要之前不接收消息

c++ - 为什么尽管使用了 -isystem,但 clang 在我的标题上报告了警告,而 gcc 没有报告?

c++ - WSI 同步子 channel 依赖和链接到颜色附件输出

Linux下获取相机照片的C程序

c - 为什么不应该在 linux 内核中将全局变量初始化为 0/NULL/false?

c++ - 如何为我的图形提供 vertex_index 属性