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. QTcpSocket and QUdpSocket on Windows 10, blocked?
Qt 6.11 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 6.7k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    Last week I wrote an application using both QTcpSocket and QUdpSocket, both worked without issues, today I started the PC and I'm not aware of any changes that have been made, also I'm wasn't aware of any dialog or prompts, however I have previous experience where on Windows 10 the sockets stop working because of the firewall.

    Is there a dialog or something I can use to resolve this problem as right now I cannot get the application to communicate. To be clear, I have two applications both using QTcpSocket and QUdpSocket, QUdpSocket is used to broadcast a heartbeat.

    There is no activity, nothing is being received the WriteDatagram method returns correctly the number of bytes written to the socket.

    Kind Regards,
    Sy

    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
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #2

        If you can run wireshark then you can sniff the traffic to see if the packets are at least getting out of the program.

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

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

          @Kent-Dorfman , thank you, downloaded and installed on the laptop, here is a screenshot.
          wireshark.png
          Not sure what I'm supposed to do now, I've tried the WiFi and I'm not seeing anything that resembles the content I'm sending. Since the function returns a positive value indicating that It has succeeded, what else can I do?

          Kind Regards,
          Sy

          KroMignonK 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @Kent-Dorfman , thank you, downloaded and installed on the laptop, here is a screenshot.
            wireshark.png
            Not sure what I'm supposed to do now, I've tried the WiFi and I'm not seeing anything that resembles the content I'm sending. Since the function returns a positive value indicating that It has succeeded, what else can I do?

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

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

            Since the function returns a positive value indicating that It has succeeded, what else can I do?

            That's not totally true, positive return value only indicates that message has been "accepted" by TCP/IP stack, that's all.

            Where are receiver and sender located? on same machine?
            Are you sure you are using right network support?
            Do you have multiple possible routes between receiver and sender?

            For WireShark you can start an listening for the UDP port you are using for your "heartbeat" signal. In filter simply enter "upd port xxx" where xxx is the port number (cf https://wiki.wireshark.org/CaptureFilters for more details).

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

              Since the function returns a positive value indicating that It has succeeded, what else can I do?

              That's not totally true, positive return value only indicates that message has been "accepted" by TCP/IP stack, that's all.

              Where are receiver and sender located? on same machine?
              Are you sure you are using right network support?
              Do you have multiple possible routes between receiver and sender?

              For WireShark you can start an listening for the UDP port you are using for your "heartbeat" signal. In filter simply enter "upd port xxx" where xxx is the port number (cf https://wiki.wireshark.org/CaptureFilters for more details).

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

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

              Kind Regards,
              Sy

              Kent-DorfmanK 1 Reply Last reply
              0
              • KroMignonK KroMignon

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

                Since the function returns a positive value indicating that It has succeeded, what else can I do?

                That's not totally true, positive return value only indicates that message has been "accepted" by TCP/IP stack, that's all.

                Where are receiver and sender located? on same machine?
                Are you sure you are using right network support?
                Do you have multiple possible routes between receiver and sender?

                For WireShark you can start an listening for the UDP port you are using for your "heartbeat" signal. In filter simply enter "upd port xxx" where xxx is the port number (cf https://wiki.wireshark.org/CaptureFilters for more details).

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

                @KroMignon , I'm now seeing the packet broadcast on WireShark, not receiving it on the other application.

                Kind Regards,
                Sy

                KroMignonK 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @KroMignon , I'm now seeing the packet broadcast on WireShark, not receiving it on the other application.

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

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

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

                    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

                                            • Login

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