Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTcpSocket and QUdpSocket on Windows 10, blocked?
Qt 6.12 LTS is out! See what's new in the release blog

QTcpSocket and QUdpSocket on Windows 10, blocked?

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 5 Posters 7.6k 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.
  • KroMignonK KroMignon

    @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

    not receiving it on the other application.

    On which port+ip have you bind you udp socket?

    SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #8

    @KroMignon , the IT department has just unlocked the app in the firewall...hopefully now it will work.

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • KroMignonK KroMignon

      @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

      not receiving it on the other application.

      On which port+ip have you bind you udp socket?

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by SPlatten
      #9

      @KroMignon , IT unlocked the firewall, I can see that the application that is broadcasting a packet using UDP is appearing on WireShark, but I am still not receiving the packet in the other application which has been unblocked in the firewall.

      The connection source for this application:

      pUDPsocket = new QUdpSocket(this);
      pUDPsocket->bind(QHostAddress::LocalHost, 8124);
      QObject::connect(pUDPsocket, &QUdpSocket::readyRead, this, &SckServer::udpRead);
      

      My slot:

      void SckServer::udpRead() {
          while( pUDPsocket->hasPendingDatagrams() ) {
              QNetworkDatagram datagram(pUDPsocket->receiveDatagram());
              ...
          }
      }
      

      It never gets into udpRead... The IP address resolves to 10.132.55.189 and the port is 8124.

      Kind Regards,
      Sy

      KroMignonK 1 Reply Last reply
      0
      • SPlattenS SPlatten

        @KroMignon , IT unlocked the firewall, I can see that the application that is broadcasting a packet using UDP is appearing on WireShark, but I am still not receiving the packet in the other application which has been unblocked in the firewall.

        The connection source for this application:

        pUDPsocket = new QUdpSocket(this);
        pUDPsocket->bind(QHostAddress::LocalHost, 8124);
        QObject::connect(pUDPsocket, &QUdpSocket::readyRead, this, &SckServer::udpRead);
        

        My slot:

        void SckServer::udpRead() {
            while( pUDPsocket->hasPendingDatagrams() ) {
                QNetworkDatagram datagram(pUDPsocket->receiveDatagram());
                ...
            }
        }
        

        It never gets into udpRead... The IP address resolves to 10.132.55.189 and the port is 8124.

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #10

        @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

        pUDPsocket->bind(QHostAddress::LocalHost, 8124);

        You should verify that bind did work:

        if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124))
        {
           qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString();
        }
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        SPlattenS 1 Reply Last reply
        0
        • KroMignonK KroMignon

          @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

          pUDPsocket->bind(QHostAddress::LocalHost, 8124);

          You should verify that bind did work:

          if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124))
          {
             qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString();
          }
          
          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #11

          @KroMignon , thank you, interesting the bind is failing:

          Failed to bind UDP socket: The address is protected.
          

          Kind Regards,
          Sy

          jsulmJ 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @KroMignon , thank you, interesting the bind is failing:

            Failed to bind UDP socket: The address is protected.
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #12

            @SPlatten For ports bellow 10.000 you need privileges (like root on UNIX).

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            SPlattenS 1 Reply Last reply
            0
            • jsulmJ jsulm

              @SPlatten For ports bellow 10.000 you need privileges (like root on UNIX).

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by SPlatten
              #13

              @jsulm , I was just looking at:
              https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports

              Whats preventing me choosing a port that is in use for something else? For example 13?

              Kind Regards,
              Sy

              KroMignonK jsulmJ 2 Replies Last reply
              0
              • SPlattenS SPlatten

                @jsulm , I was just looking at:
                https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports

                Whats preventing me choosing a port that is in use for something else? For example 13?

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #14

                @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

                Whats preventing me choosing a port that is in use for something else? For example 13?

                As already written by @jsulm , port numbers bellow 1000 are reserved for system. You need to have root rights to bind on them.
                This is called security ;)

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @jsulm , I was just looking at:
                  https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports

                  Whats preventing me choosing a port that is in use for something else? For example 13?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #15

                  @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

                  Whats preventing me choosing a port that is in use for something else?

                  From the link you posted (and what I wrote before): "On Unix-like operating systems, a process must execute with superuser privileges to be able to bind a network socket to an IP address using one of the well-known ports."

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by SPlatten
                    #16

                    @KroMignon , @jsulm , ok, I've changed the port to 30119 for UDP communications, which seems to work on one application, on the other application that is going to receive the broadcasts and act on them I'm getting:

                    Failed to bind UDP socket: The bound address is already in use
                    

                    Both applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?

                    Kind Regards,
                    Sy

                    KroMignonK 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      @KroMignon , @jsulm , ok, I've changed the port to 30119 for UDP communications, which seems to work on one application, on the other application that is going to receive the broadcasts and act on them I'm getting:

                      Failed to bind UDP socket: The bound address is already in use
                      

                      Both applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by
                      #17

                      @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

                      Both applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?

                      Do you want to bind each socket on same port?
                      So you have allow reusing same port:

                      if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint))
                      {
                         qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString();
                      }
                      

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      SPlattenS 2 Replies Last reply
                      0
                      • KroMignonK KroMignon

                        @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

                        Both applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?

                        Do you want to bind each socket on same port?
                        So you have allow reusing same port:

                        if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint))
                        {
                           qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString();
                        }
                        
                        SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by
                        #18

                        @KroMignon , thank you, I literally just added exactly that, compiling now and will try.

                        Kind Regards,
                        Sy

                        1 Reply Last reply
                        0
                        • KroMignonK KroMignon

                          @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

                          Both applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?

                          Do you want to bind each socket on same port?
                          So you have allow reusing same port:

                          if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint))
                          {
                             qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString();
                          }
                          
                          SPlattenS Offline
                          SPlattenS Offline
                          SPlatten
                          wrote on last edited by
                          #19

                          @KroMignon , its working :)

                          Kind Regards,
                          Sy

                          1 Reply Last reply
                          0
                          • SPlattenS SPlatten

                            @KroMignon , yes, presently both the sender and receiving applications are running on the same laptop.

                            The problem I'm having is the laptop is so locked down by the company IT that I'm not sure if it is causing problems, as I said, last week these same applications were communicating.

                            I will try capturing data on WireShark for the UDP port.

                            I've just added filter to WireShark:

                            udp.port eq 8124
                            

                            8124 is the port I'm using to broadcast on, I've also modified my source to:

                            writeDatagram(bytaryDoc, QHostAddress::Broadcast, suint16Port);
                            

                            Seeing nothing in WireShark.

                            Kent-DorfmanK Offline
                            Kent-DorfmanK Offline
                            Kent-Dorfman
                            wrote on last edited by
                            #20

                            @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

                            The problem I'm having is the laptop is so locked down by the company IT that I'm not sure if it is causing problems, as I said, last week these same applications were communicating.

                            And therein is the problem...and it ticks me off to no end. If you cannot own and control your dev resources then you're just whizzin in the wind when you need to do real work. These dumb-acre kids who think they know and understand network security need to be taken to the wood shed and whipped with a willow switch when they start treating devs like office admin workers.

                            The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

                            SPlattenS 1 Reply Last reply
                            0
                            • Kent-DorfmanK Kent-Dorfman

                              @SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:

                              The problem I'm having is the laptop is so locked down by the company IT that I'm not sure if it is causing problems, as I said, last week these same applications were communicating.

                              And therein is the problem...and it ticks me off to no end. If you cannot own and control your dev resources then you're just whizzin in the wind when you need to do real work. These dumb-acre kids who think they know and understand network security need to be taken to the wood shed and whipped with a willow switch when they start treating devs like office admin workers.

                              SPlattenS Offline
                              SPlattenS Offline
                              SPlatten
                              wrote on last edited by
                              #21

                              @Kent-Dorfman , this is a large corporate company dealing with the ministry of defence they take security and IT very seriously...it does make life very difficult, but they have deep pockets so the cost doesn't hurt them so much.

                              Kind Regards,
                              Sy

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                DominicLeer
                                wrote on last edited by
                                #22

                                You can check the Windows 10 firewall settings to make sure that your applications are allowed through. Just search for ""firewall"" in the Start menu and click on ""Windows Defender Firewall"". From there, you can click on ""Allow an app or feature through Windows Defender Firewall"" and make sure that your applications are checked.

                                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
                                • Unsolved