Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

No network interfaces have flag "CanMulticast" in Windows UWP app



  • I printed the flags for network interfaces and they show that no interface has CanMulticast flag set.
    So I believe that is the reason, why socket fails to join multicast group.
    The same code runs just fine on Windows (non-UWP), Ubuntu, Android, iOS.
    I run this sample on Windows under Virtualbox. But I also tested in real Windows machine and Windows tablet.

    Here is the code:

        if (m_multicastSocket->state() != QAbstractSocket::BoundState) {
            if (!m_multicastSocket->bind(QHostAddress::AnyIPv4, MULTICAST_HELLO_PORT, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint)) {
                LOGW << "Error: Failed to bind multicast socket!";
                return;
            }
            else
                LOGD << "Successfully bound to multicast HELLO port:" << MULTICAST_HELLO_PORT;
    
            const QString& ifName = ClientNetworkManager::instance().desiredInterfaceName();
            if (!ifName.isEmpty())
                m_multicastSocket->setMulticastInterface(QNetworkInterface::interfaceFromName(ifName));
    
            for (const auto& i : QNetworkInterface::allInterfaces()) {
                LOGW << "Interface:" << i.name() << "loopback:" << bool(i.flags() & QNetworkInterface::IsLoopBack)
                     << "\nrunning:" << bool(i.flags() & QNetworkInterface::IsRunning)
                     << "\nmulticast:" <<bool(i.flags() & QNetworkInterface::CanMulticast)
                     << "\naddress is empty:" << i.addressEntries().isEmpty();
    
                if (!(i.flags() & QNetworkInterface::IsLoopBack)
                        && (i.flags() & QNetworkInterface::IsRunning)
                        && (i.flags() & QNetworkInterface::CanMulticast)
                        && (!i.addressEntries().isEmpty()))
                {
                    if (!m_multicastSocket->joinMulticastGroup(QHostAddress(MULTICAST_HELLO_GROUP), i)) {
                        LOGW << "Error: Joining multicast group failed on interface" << i.name() << i.humanReadableName() << i.hardwareAddress() << "with error:" << m_multicastSocket->errorString();
                    }
                    else
                        LOGW << "Successfully joined multicast group on interface" << i.name() << i.humanReadableName() << i.hardwareAddress();
                }
            }
        }
    

    The log output is:

    Successfully bound to multicast HELLO port: 55555
    
    Interface: "{76FCD10B-5F45-4155-9C42-31960A66A6E2}" loopback: false 
    running: true 
    multicast: false 
    address is empty: false
    
    Interface: "{76FCD10B-5F45-4155-9C42-31960A66A6E2}" loopback: false 
    running: true 
    multicast: false 
    address is empty: true
    

    The log for the same app rebuilt as normal Windows app:

    Successfully bound to multicast HELLO port: 55555
    
    Interface: "ethernet_32771" loopback: false
    running: true
    multicast: true
    address is empty: false
    Successfully joined multicast group on interface "ethernet_32771" "vEthernet (Default Switch) 2" "50:15:5D:D0:DB:77"
    
    Interface: "ethernet_32774" loopback: false
    running: true
    multicast: true
    address is empty: false
    Successfully joined multicast group on interface "ethernet_32774" "Ethernet 2" "08:00:27:DC:00:5D"
    
    Interface: "loopback_0" loopback: true
    running: true
    multicast: true
    address is empty: false
    
    Interface: "ethernet_32780" loopback: false
    running: true
    multicast: true
    address is empty: false
    Successfully joined multicast group on interface "ethernet_32780" "vEthernet (nat) 2" "00:15:5D:C8:5C:2A"
    

    QT multicastreceiver example produces the same results.

    Do you have any hints?


Log in to reply