本文介绍了使用ShareAddress的多播的QUdpSocket绑定失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在另一个进程已经绑定到指定端口上的情况下,下面的简单代码在带有QT5.2的Windows上失败。然而,ShareAddress标志应该允许绑定多次。在MacOSX它工作正常。

  if(false == bind(QHostAddress :: AnyIPv4,port_,QUdpSocket :: ShareAddress) 
{
qDebug()<< Warn:不能绑定到多播端口<港口_;
qDebug()<<错误();
}
joinMulticastGroup(QHostAddress(address_));

这是QT中的错误吗?

解决方案

如果是的话,在中说明,在Windows平台上忽略ShareAddress

我从来没有测试过这个解决方案, $ c> QUdpSocket :: ReuseAddressHint 作为Windows的替代标志。


The simple code belows fails on Windows with QT5.2 when another process is already bound on the specified port. The ShareAddress flag should allow binding multiple times however. On MacOSX it works fine.

if (false == bind(QHostAddress::AnyIPv4, port_, QUdpSocket::ShareAddress))
{
    qDebug() << "Warn: cannot bind to the multicast port " << port_;
    qDebug() << error();
}
joinMulticastGroup(QHostAddress(address_));

Is it a bug in QT ? If so is there a workaround ?

Thanks.

解决方案

As stated in the documentation, ShareAddress is ignored on Windows platform.

I never test this solution, but in my understanding, you can try to use QUdpSocket::ReuseAddressHint as alternative flags for Windows.

这篇关于使用ShareAddress的多播的QUdpSocket绑定失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 08:02