Important: Please read the Qt Code of Conduct -

QTcpServer not reachable outside

  • Hi,
    I run QTcpServer and listen(QHostAddress::Any, 8081);. The server is reachable on localhost:8081. However, it is not reachable on ( 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

  • Moderators

    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;
    Q_ASSERT( !address.isNull() );
    server->listen( address, 8081 );

  • The foreach loop returns these addresses on the PC:


    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, doesn't work.

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

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

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

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

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

Log in to reply