QTcpSocket why SocketTimeoutError is raised ?
-
@CHPOG If you want to check whether open or not call https://doc.qt.io/qt-5/qiodevice.html#isOpen not open()
-
@JonB said in QTcpSocket why SocketTimeoutError is raised ?:
but he didn't respond....
This is often the case...
-
Thanks for your answer and sorry if I didn't directly try what you said @JonB .
So I try to remove all the call to open(). I call open() in my constructor of my Rs232 object and connectToHost in the object of my socket connection.
I had the same error raised.
But right to check that connection is open isOpen works fine.
But as I have this socketTimeoutError my tests fails. -
@CHPOG said in QTcpSocket why SocketTimeoutError is raised ?:
I call open() in my constructor of my Rs232 object and connectToHost in the object of my socket connection.
Why do you call open()? connectToHost() is enough.
-
@jsulm
Sorry if I am not really clear.
But I have two classes one for a RS232 which call open() in the constructor.
An other one for Socket which call connectToHost() in the constructor.
So for now I am not calling open() for Socket connection. I only use connectToHost().
And the SocketTimeouError is still raised. -
@CHPOG You wrote: "But when I want to check that my socket is correctly open by QVERIFY(socket->open() ==true) the test fails". So, you do call open() to check whether the socket is open? If so, then please change it to isOpen().
-
To be easier for everyone to understand I test with a main and get the same error.
#include <QCoreApplication> #include <QTcpSocket> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QTcpSocket *socket = new QTcpSocket(); socket->connectToHost("10.1.0.1",1470); socket->write("list\r"); QString fullData; int maxSize = 5000; //We wait end of data transmission but not too much if device is in start mode while(socket->waitForReadyRead(1000) && fullData.size() < maxSize) { QByteArray data = socket->readAll(); //Removing TCP header data.remove(0,32); //qDebug()<< "data added " << data.toHex(); QString dataAsString(data); //qDebug()<< "data added in string " << dataAsString; fullData.append(dataAsString); } qDebug()<< "isWaitingForCommand " << fullData; qDebug()<< "ERROR = " << socket->errorString(); socket->close(); return a.exec(); }
I can do more simple. And I always do not understood why this error is raised.
Below this is the ouput :isWaitingForCommand "; value ; unity ; minimum value ; maximum value ; description\r\nsample_rate ; 800 ; Hz ; 200 ; 1100 ; FrÚquence d'Úchantillonnage de la centrale ADIS ; \r\nsensors ; 7 ; ; 1 ; 7 ; Capteurs actifs (BIT0=gyros BIT1=accÚlÚros BIT2=magnÚtos) ; \r\nsynchro ; 0 ; ; 0 ; 1 ; Active l'emission d'un 0x02 en dÚbut de trame ; \r\ncounter ; 0 ; ; 0 ; compteur de trame avant les donnÚes capteurs ; \r\nbt_rate ; 230400 ; ; 115200 ; 230400 ; Baudrate pour la communication bluetooth ; \r\npassword ; 0 ; ; 0 ; 999999 ; Mot de passe pour accÞs aux paramÞtres systÞmes ; \r\nsensor$ " ERROR = "Network operation timed out"
-
@CHPOG since you insist on using the synchronous api, you should at least use https://doc.qt.io/qt-5/qabstractsocket.html#waitForConnected
for the connection to the host to be established...