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. QTcpServer not reachable outside
Qt 6.11 is out! See what's new in the release blog

QTcpServer not reachable outside

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 3.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.
  • M Offline
    M Offline
    MartinD
    wrote on last edited by MartinD
    #1

    Hi,
    I run QTcpServer and listen(QHostAddress::Any, 8081);. The server is reachable on localhost:8081. However, it is not reachable on 192.168.1.1:8081 (192.168.1.1 is local IP of the PC where the server runs). I completely turned off firewall. I use Windows 10. I also tried to run my server with admin privileges.

    How to access my server on 192.168.1.1:8081?

    raven-worxR 1 Reply Last reply
    0
    • M MartinD

      Hi,
      I run QTcpServer and listen(QHostAddress::Any, 8081);. The server is reachable on localhost:8081. However, it is not reachable on 192.168.1.1:8081 (192.168.1.1 is local IP of the PC where the server runs). I completely turned off firewall. I use Windows 10. I also tried to run my server with admin privileges.

      How to access my server on 192.168.1.1:8081?

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

      @MartinD
      instead of binding it to QHostAddress::Any, iterate over the available adresses and use the the address from the LAN interface you want the server to be available on:

      QHostAddress address;
      foreach(QHostAddress a, QNetworkInterface::allAddresses())
      {
      	// use the first non-localhost IPv4 address
      	if( a != QHostAddress::LocalHost && a.toIPv4Address() )
      	{
      		address = a;
      		break;
      	}
      }
      ...
      Q_ASSERT( !address.isNull() );
      server->listen( address, 8081 );
      

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

      1 Reply Last reply
      1
      • M Offline
        M Offline
        MartinD
        wrote on last edited by
        #3

        The foreach loop returns these addresses on the PC:

        QHostAddress("169.254.195.225")
        QHostAddress("169.254.187.118")
        QHostAddress("192.168.1.1")
        QHostAddress("169.254.45.48")

        I don't know what 169.254.x.x adresses are (as I use 192.168.1.x IP address range for my LAN). Anyway, listening on the first IP, which is 169.254.195.225, doesn't work.

        I also tried to hardcode listen(QHostAddress("192.168.1.1")) and this also doesn't work - the server is not reachable on localhost::8081 and on 192.168.1.1:8081.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          LuGRU
          wrote on last edited by
          #4

          If You're using some sort of firewall make sure FW don't block Your app.
          Using QHostAddress::Any will force server to listen on all available interfaces.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MartinD
            wrote on last edited by
            #5

            As I already mentioned, the firewall is completely off (I use Windows 10 built-in firewall). I also have Avast - is there anything that could block ingoing traffic to my PC?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              LuGRU
              wrote on last edited by
              #6

              In old days (XP) when app was in FW and FW was disabled sometimes it did blocked app anyways, so better to double check if app is listed there.

              Avast - dunno don't use.

              Additionally check if listen() return true, i.e.:

                  if (!_tcpServer->listen(QHostAddress::Any, port)) {
                      qDebug() << "server error unable to listen:"
                               << _tcpServer->errorString();
                  } else {
                      qDebug() << "tcp server listen on:"
                               << _tcpServer->serverAddress()
                               << _tcpServer->serverPort()
                                  ;
                  }
              

              Maybe another app uses port, i.e. Skype.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MartinD
                wrote on last edited by
                #7

                It seems that the problem is connected with Microsoft Edge browser which blocks http request to my QTcpServer. When I run http://192.168.1.1:8081 in Edge I don't receive incoming connection in my QTcpServer. When I run http://192.168.1.1:8081 in any other browser, or http://localhost:8081 in Edge, it works.

                1 Reply Last reply
                1

                • Login

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