QTcpSocket NetworkError with Wifi OK but Internet NOK
-
I can confim you guys that the issue comes from the client side.
With my client offline (so no ethernet cable plugged in), I can connect the PC to the raspberry in SSH with Putty or cmd.
So in Qt, I decided to change the port number to 22 (ssh) in _client->connectToHost(ip, port 22). The behavior is exactly the same as explained before. It fails when the client is offline, it works when the client is online.
So the issue comes from Qt, or my code. But I don't know what. -
Hello !
After a few days of digging, here is the situation:
I use QTCPSocket to transfer datas from a Windows client to a Linux system server.The server is configured as a Wifi AP without internet connection.
When the client is connected to the server through Wifi, without internet, I hit NetworkError as soon as I try send/receive datas.
But if the client is additionnaly connected to internet through ethernet, everything works perfectly.
Can someone helps me / explain me the issue please ? ?
@Match0um said in QTcpSocket NetworkError with Wifi OK but Internet NOK:
I hit NetworkError
Could you please share the error? Specially the error string...
-
@Match0um said in QTcpSocket NetworkError with Wifi OK but Internet NOK:
I hit NetworkError
Could you please share the error? Specially the error string...
@Pablo-J-Rogina Hi, here is how I manage errors (I added the error string) :
connect(_client, SIGNAL(error(QAbstractSocket::SocketError)), this SLOT(error(QAbstractSocket::SocketError)));
void myClass::error(QAbstractSocket::SocketError error) { qDebug() << "ERROR " << error; qDebug()<< "Error string "<<_client.errorString(); }
So in the App output I get :
"ERROR QAbstractSocket::NetworkError".
Error string "Host unreachable"I also ran my code in debug mode but I have no additionnal information about the error :/
-
Ok guys, I finally found what causes the problem :
It is in my method connectionWifi() :
void MyClass::connectionWifi() { _connectionAttempts++; qDebug()<<"@@ Connection wifi"; QString resultDisk; QProcess process; int returnCode = process.execute("netsh wlan connect name=wifiAp"); process.start("netsh wlan show networks"); process.waitForFinished(); resultDisk = process.readAllStandardOutput(); if(returnCode==0){ if(resultDisk.contains("wifiAp")){ ui->label_statutWifi->setText(tr("Détecté")); connection(); }else{ ui->label_statutWifi->setText(tr("Non connecté")); ui->label_connect->setText(tr("Outil non détecté")); } }else{ ui->label_statutWifi->setText(tr("Wifi de la tablette éteind")); ui->label_connect->setText(tr("Activez le WiFi")); } }
If I comment this line it works well :
int returnCode = process.execute("netsh wlan connect name=wifiAp");
I don't know why this line makes the code not working when the the ethernet cable is unplugged (the ethernet network has no link with the wifi network I am trying to connect to).
-
Ok guys, I finally found what causes the problem :
It is in my method connectionWifi() :
void MyClass::connectionWifi() { _connectionAttempts++; qDebug()<<"@@ Connection wifi"; QString resultDisk; QProcess process; int returnCode = process.execute("netsh wlan connect name=wifiAp"); process.start("netsh wlan show networks"); process.waitForFinished(); resultDisk = process.readAllStandardOutput(); if(returnCode==0){ if(resultDisk.contains("wifiAp")){ ui->label_statutWifi->setText(tr("Détecté")); connection(); }else{ ui->label_statutWifi->setText(tr("Non connecté")); ui->label_connect->setText(tr("Outil non détecté")); } }else{ ui->label_statutWifi->setText(tr("Wifi de la tablette éteind")); ui->label_connect->setText(tr("Activez le WiFi")); } }
If I comment this line it works well :
int returnCode = process.execute("netsh wlan connect name=wifiAp");
I don't know why this line makes the code not working when the the ethernet cable is unplugged (the ethernet network has no link with the wifi network I am trying to connect to).
@Match0um said in QTcpSocket NetworkError with Wifi OK but Internet NOK:
int returnCode = process.execute("netsh wlan connect name=wifiAp");
Try unplugging ethernet cable and run
netsh wlan connect name=wifiAp
from a Command Prompt. What happens, does it block? -
@Match0um said in QTcpSocket NetworkError with Wifi OK but Internet NOK:
int returnCode = process.execute("netsh wlan connect name=wifiAp");
Try unplugging ethernet cable and run
netsh wlan connect name=wifiAp
from a Command Prompt. What happens, does it block? -
Then try again in your code but building the parameter list rather than passing the complete command as a string.
I guess there's an issue with the = part.
-
This post is deleted!
-
Then try again in your code but building the parameter list rather than passing the complete command as a string.
I guess there's an issue with the = part.
@SGaist Did you mean something like that ? :
QString cmd = "netsh"; QStringList arguments; arguments <<"wlan"<<"connect"<<"name=mScan"; int returnCode = process.execute(cmd, arguments);
It doesn't change the behavior, I have the output "the connection request was successful", it connects my PC to the wifi access point, but if I run this commend the connectToHost method hits NetworkError.
-
@SGaist Did you mean something like that ? :
QString cmd = "netsh"; QStringList arguments; arguments <<"wlan"<<"connect"<<"name=mScan"; int returnCode = process.execute(cmd, arguments);
It doesn't change the behavior, I have the output "the connection request was successful", it connects my PC to the wifi access point, but if I run this commend the connectToHost method hits NetworkError.
-
@Pablo-J-Rogina Hi, here is how I manage errors (I added the error string) :
connect(_client, SIGNAL(error(QAbstractSocket::SocketError)), this SLOT(error(QAbstractSocket::SocketError)));
void myClass::error(QAbstractSocket::SocketError error) { qDebug() << "ERROR " << error; qDebug()<< "Error string "<<_client.errorString(); }
So in the App output I get :
"ERROR QAbstractSocket::NetworkError".
Error string "Host unreachable"I also ran my code in debug mode but I have no additionnal information about the error :/
@Match0um said in QTcpSocket NetworkError with Wifi OK but Internet NOK:
Error string "Host unreachable"
This is a routing issue. You may want to capture and analyze network traffic (i.e. using Wireshark) to see what's going on under your Qt app depending on what connections (wireless or wired) you have on your client PC