Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUdpSocket Multicast can't receive
Forum Updated to NodeBB v4.3 + New Features

QUdpSocket Multicast can't receive

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 3.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    w.tkm
    wrote on last edited by w.tkm
    #1

    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

    raven-worxR 1 Reply Last reply
    1
    • W w.tkm

      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

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @w-tkm
      i guess you should bind on QHostAddress::Broadcast host address

      Make sure that the local ip host address used for bind is correct and the same the multi cast happens.
      Also check possible firewall settings.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      W 1 Reply Last reply
      1
      • nageshN Offline
        nageshN Offline
        nagesh
        wrote on last edited by
        #3

        @w-tkm Did you try running multicast receiver qt example application?

        W 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @w-tkm
          i guess you should bind on QHostAddress::Broadcast host address

          Make 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 Offline
          W Offline
          w.tkm
          wrote on last edited by
          #4

          @raven-worx
          I have checked them over and over again, all the basic issues have been checked.
          There is absolutely no problem with them.

          1 Reply Last reply
          0
          • nageshN Offline
            nageshN Offline
            nagesh
            wrote on last edited by
            #5

            @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?

            1 Reply Last reply
            0
            • nageshN nagesh

              @w-tkm Did you try running multicast receiver qt example application?

              W Offline
              W Offline
              w.tkm
              wrote on last edited by w.tkm
              #6

              @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

              1 Reply Last reply
              0
              • nageshN Offline
                nageshN Offline
                nagesh
                wrote on last edited by
                #7

                @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 ?"

                W 1 Reply Last reply
                0
                • nageshN nagesh

                  @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 ?"

                  W Offline
                  W Offline
                  w.tkm
                  wrote on last edited by w.tkm
                  #8

                  @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.

                  https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/automatic-metric-for-ipv4-routes

                  1 Reply Last reply
                  0
                  • ThirdStrandT Offline
                    ThirdStrandT Offline
                    ThirdStrand
                    wrote on last edited by ThirdStrand
                    #9

                    @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

                    1 Reply Last reply
                    0
                    • ThirdStrandT Offline
                      ThirdStrandT Offline
                      ThirdStrand
                      wrote on last edited by ThirdStrand
                      #10

                      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();
                          }
                      
                      1 Reply Last reply
                      1
                      • ThirdStrandT Offline
                        ThirdStrandT Offline
                        ThirdStrand
                        wrote on last edited by
                        #11

                        also::

                        https://stackoverflow.com/questions/19218994/qt-joinmulticastgroup-for-all-interface

                        Helps to use the various indications/flags in the QNetworkInterface object also.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved