Solved QWebSocket is not able to connect server
-
Do you have access to the server? Does the server have anything to say?
-
@manordheim as I said in the previous message, I'm able to connect the server (it is my program running on the same machine) by a web page and websocket library via Javascript.
They communicate correctly. -
@Bonnie I mean that I run the program, then I shut down the program by Alt-F4.
I start a 10-minutes test ... -
@Bonnie
Right now the connection is hosted in the constructor of a global object./** * @brief IoBoard::IoBoard */ IoBoard::IoBoard(QObject* parent) : QObject(parent) { qDebug() << "Costruttore IoBoard"; // -- websocket QObject::connect( &_ws, &QWebSocket::connected, this, &IoBoard::onConnected); QObject::connect( &_ws, &QWebSocket::disconnected, this, &IoBoard::onDisconnected); QObject::connect( &_ws, &QWebSocket::destroyed, this, &IoBoard::onDestroyed); QObject::connect( &_ws, &QWebSocket::stateChanged, this, &IoBoard::onStateChanged); connect( &_ws, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), [=](QAbstractSocket::SocketError error){ qDebug() << "[IoBoard] Errore: " << error; } ); QUrl url ("ws://localhost:7681"); // url.setHost("10.191.40.216"); qDebug() << "[IoBoard] url: " << url.toString() << " - Scheme: " << url.scheme() << " - Host: " << url.host() << " - Port: " << url.port(); qDebug() << "[IoBoard] state:" << _ws.state(); _ws.open(url); qDebug() << "[IoBoard] state:" << _ws.state(); }
-
@Bonnie
More than half an hour and nothing is notified.
I also press some buttons and return but websocket does not notify anything.Costruttore IoBoard [IoBoard] url: "ws://localhost:7681" - Scheme: "ws" - Host: "localhost" - Port: 7681 [IoBoard] state: QAbstractSocket::UnconnectedState [IoBoard] StateChanged: QAbstractSocket::ConnectingState [IoBoard] state: QAbstractSocket::ConnectingState Costruttore Cassetti QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed. [Cassetti] open: true >> cassetti: 19 Costruttore Prenotazioni Platform: "xcb" Farmacia: "Locker 1 - Gruppo AC - Roman" Cassetti: "99" serial: "ttyS1" [CheckCode] Tipo: 0 - Code: "99887766" qml: onActFocCh qml: OK - 123 qml: OK - 123 qml: onActFocCh qml: onActFocCh qml: onActFocCh qml: onActFocCh qml: onActFocCh qml: onActFocCh qml: onActFocCh
-
What's you Qt version?
Can you provide a minimal code example for others to test? -
Hi @SteMMo,
Have you already tried the Echo Client Example and checked if that can connect to your server?
Btw, Qt 5.7.1 is quite old. Can you update to a newer version?
Regards
-
@aha_1980 Hi,
at the moment, no.
The boards on the field mount an old OS (Debian stretch); this repository provides version 5.7.1
Maybe in the future I'll be able to move on a new version (buster) -
@aha_1980 I tried the sample and yes, it worked:
root@tinkerboard:/home/amtek/echoClient# ./echoclient -d WebSocket server: QUrl("ws://localhost:7681") WebSocket connected Message received: "Unk"
I don't understand: my code for IoBoard is basically started from the code of EchoClient class .. the code is included in a past message ..
-
Solved!
Comparing main.cpp file I found that the definition of IoBoard object was static and global (outside the main() function).
Now I defined the object inside the main() function and the connection is done. -