QUdpSocket Multicast can't receive
-
QUdpSocket Multicast can't receive, but problem is not found.
It's not that I can't do it completely, I can receive it by setting Metric from the network settings.My code:
m_pUdpSockRecv = new QUdpSocket(this); connect(m_pUdpSockRecv, SIGNAL( readyRead() ), this, SLOT( fnUdpRecvData() )); m_pUdpSockRecv->bind( QHostAddress( m_strLocalIp ) , m_numConnectPort, QAbstractSocket::DefaultForPlatform); m_pUdpSockRecv->joinMulticastGroup( QHostAddress( m_strConnectHostIp ) );The problem is that even though both bind and joinMulticastGroup are true, readyRead is not emitted.
I've already confirmed that I'm receiving at Wireshark, the firewall is turned off, and the ping with the destination goes through.The only thing I can think of is the Multicast setting, but is there some special setting I need to do?
My environment:
OS: Windows 10
Qt : 5.15.0
Kit: MSVC2019 64bit -
QUdpSocket Multicast can't receive, but problem is not found.
It's not that I can't do it completely, I can receive it by setting Metric from the network settings.My code:
m_pUdpSockRecv = new QUdpSocket(this); connect(m_pUdpSockRecv, SIGNAL( readyRead() ), this, SLOT( fnUdpRecvData() )); m_pUdpSockRecv->bind( QHostAddress( m_strLocalIp ) , m_numConnectPort, QAbstractSocket::DefaultForPlatform); m_pUdpSockRecv->joinMulticastGroup( QHostAddress( m_strConnectHostIp ) );The problem is that even though both bind and joinMulticastGroup are true, readyRead is not emitted.
I've already confirmed that I'm receiving at Wireshark, the firewall is turned off, and the ping with the destination goes through.The only thing I can think of is the Multicast setting, but is there some special setting I need to do?
My environment:
OS: Windows 10
Qt : 5.15.0
Kit: MSVC2019 64bit@w-tkm
i guess you should bind onQHostAddress::Broadcasthost addressMake sure that the local ip host address used for bind is correct and the same the multi cast happens.
Also check possible firewall settings. -
@w-tkm
i guess you should bind onQHostAddress::Broadcasthost addressMake sure that the local ip host address used for bind is correct and the same the multi cast happens.
Also check possible firewall settings.@raven-worx
I have checked them over and over again, all the basic issues have been checked.
There is absolutely no problem with them. -
@w-tkm said in QUdpSocket Multicast can't receive:
m_pUdpSockRecv->joinMulticastGroup( QHostAddress( m_strConnectHostIp ) )@w-tkm The address used in Joinmulticastgroup is multicast series ip address right?
-
@nagesh
I've already tried running it.
I used an example application for the sender as well, but only the first time the readyRead emitted.
It must have been sent many times, but only the first time.
And what I am wondering is that if I run the receiver first, it will not receive.
Sorry, example application can receive.
However, the data sent by sender my application is not received by receiver qt example application.
My sender application is written in VC++.yes,I use multicast series ip address.
I use 239.0.0.20 -
@w-tkm what does this mean?
I can receive it by setting Metric from the network settings.in what setting you are able to receive it?
Do mean by adding "route add ?"
@naesh
From the Control Panel, in the Network Settings, uncheck "Automatic Metric" and set the metric for the interface to 1.
For more information on metrics, see the following. -
@raven-worx , you are not alone. This is a very frustrating situation.
Anyone have any repeatable configuration/solution? The Metric "trick" is not working in Win10 Pro 20H2. At least for not more than one time of program execution after a full reboot.
Bind to the IPv4 address (Ethernet nic) and specific port is successful, and shows in netstat. Joining the multicast group is reported successful by QUdpSocket also. No firewall in the picture. EDIT: Wireshark shows that the data is flowing periodically as expected.
Whether Qt pops readyRead is a crap shoot. It happens once in a while as expected and I think I have it "fixed", then a restart of the program causes it to fail once again.
Example "multicastreceiver" application has never worked on Win10 for me.
Qt 5.15.0 MinGW 64 bit, Win10 Pro
-
Interesting:
In Linux Qt 5.15.0 (same version) gcc, binding to the Multicast IPv4 QHostAddress works, then join to the multicast group with the same address. MC datagrams flow like butter!
There are evidently significant differences in how UDP and Multicast work between the two OS's.
In Windows here is what is working for me now (and hopefully will also work in Linux). It feels sort of brute force, but happily now things are consistently working in Windows. This is sort of the hard way, but demonstrates how to navigate the various properties and flags. One could just as easily only look at the addresses list and choose the address that you bound the UDP socket to originally.
// Windows is weird QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces(); // Try the multicast UDP socket for SA first saMC = new QUdpSocket(this); saMC->setSocketOption(QAbstractSocket::LowDelayOption, 1); //saMC->setSocketOption(QAbstractSocket::KeepAliveOption, 1); connect(saMC, &QUdpSocket::readyRead, this, &Commander::handleDatagram, Qt::UniqueConnection); if(saMC->bind(QHostAddress("192.168.0.51"), 6969, QUdpSocket::ShareAddress|QUdpSocket::ReuseAddressHint)) { foreach(QNetworkInterface interface, interfaces) { qDebug()<<"interface:"<<interface.isValid()<<interface.flags(); QNetworkInterface::InterfaceFlags iflags = interface.flags(); if(interface.isValid() && !iflags.testFlag(QNetworkInterface::IsLoopBack) && iflags.testFlag(QNetworkInterface::CanMulticast) && iflags.testFlag(QNetworkInterface::IsRunning)) { QList<QNetworkAddressEntry> addressEntries = interface.addressEntries(); for (int i = 0; i < addressEntries.length(); i++) { QNetworkAddressEntry ae = addressEntries.at(i); if (ae.ip().protocol() == QAbstractSocket::IPv4Protocol) { qDebug()<<"\nSA bound...join mc group:"<<saMC->joinMulticastGroup(QHostAddress("239.2.3.1"), interface); } else { qDebug()<<"\nSA bound...failed to join mc group on interface:"<<addressEntries[i].ip(); } } } } } else { qDebug()<<"SA multicast socket unable to bind...."<<saMC->errorString(); } -
also::
https://stackoverflow.com/questions/19218994/qt-joinmulticastgroup-for-all-interface
Helps to use the various indications/flags in the QNetworkInterface object also.