zoukankan      html  css  js  c++  java
  • Qt-报错 QNativeSocketEngine::joinMulticastGroup() was not called in QAbstractSocket::BoundState

    相关资料:

    https://blog.csdn.net/xinguhong4645/article/details/99581508

    https://blog.csdn.net/wg8826/article/details/80818673

    CSDN:编写Qt udpsocket网络编程组播时候提示
    :报错 QNativeSocketEngine::joinMulticastGroup() was not called in QAbstractSocket::BoundState
    原因:需要将端口号选择可以复用。修改代码如下

    udpsocket->bind(QHostAddress::AnyIPv4,8888);
    1
    改为

    //绑定
    udpsocket->bind(QHostAddress::AnyIPv4,8888,QUdpSocket::ShareAddress|QUdpSocket::ReuseAddressHint);
    1
    2
    即可。

    -------------------------------------------------------------------------

    QUdpSocket *revWBudp;

    revWBudp = new QUdpSocket;

    //绑定本地端口

    revWBudp->bind(QHostAddress::AnyIPv4, multicastPort, QUdpSocket::NotShareAddress);

    //加入组播组

    bool result = revWBudp->joinMulticastGroup(QHostAddress(multicastIP));//这行报错

    QUdpSocket::NotShareAddress
    改为
    QUdpSocket::ShareAddress即可
    结果如下:
    QUdpSocket *revWBudp;

    revWBudp = new QUdpSocket;

    //绑定本地端口

    revWBudp->bind(QHostAddress::AnyIPv4, multicastPort, QUdpSocket::ShareAddress);

    //加入组播组

    bool result = revWBudp->joinMulticastGroup(QHostAddress(multicastIP));


     

    作者:疯狂Delphi
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

    欢迎关注我,一起进步!扫描下方二维码即可加我

  • 相关阅读:
    如何把一个一般的git库变成“裸库”?
    MacOSX下杀掉sudo进程
    nginx FastCGI错误Primary script unknown解决办法
    Lua继承userdata
    Unity图文混排
    C++轻量级跨平台文件系统API
    lua_next()
    重载方法匹配算法
    C++模板函数只能全特化不能偏特化
    xcode离线安装包下载
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/15262709.html
Copyright © 2011-2022 走看看