Unsolved 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 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?
-
@MartinD
instead of binding it toQHostAddress::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 );
-
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.
-
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 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.