QWebSocket is not able to connect server
-
@Bonnie
Added a new slot, now the debug output is:[IoBoard] url: "ws://localhost:7681" - Scheme: "ws" - Host: "localhost" - Port: 7681 [IoBoard] state: QAbstractSocket::UnconnectedState [IoBoard] StateChanged: QAbstractSocket::ConnectingState [IoBoard] state: QAbstractSocket::ConnectingState ... [IoBoard] Destroyed QObject::connect: Cannot connect (null)::destroyed() to QHostInfoLookupManager::waitForThreadPoolDone() -
Do you have access to the server? Does the server have anything to say?
-
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. -
@SteMMo
When you said "exit of the program", did you exit manually? Or the program just ends?
If you exit manually, how about waiting for like 10 minutes before your exit?
If your project is simple, it might also help if you post more code. -
@SteMMo
When you said "exit of the program", did you exit manually? Or the program just ends?
If you exit manually, how about waiting for like 10 minutes before your exit?
If your project is simple, it might also help if you post more code.@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 I mean that I run the program, then I shut down the program by Alt-F4.
I start a 10-minutes test ...@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 -
@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: onActFocChHi @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
-
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
-
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 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.