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));

 


 

posted on 2021-09-13 15:42  疯狂delphi  阅读(2045)  评论(0编辑  收藏  举报

导航