Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QWebSocket open timeout
mistralegna last edited by
I am using a QWebSocket. I try to open a connection to a secure websocket server. The connection is ok when I use the correct address (wss://), but if I use the address starting by 'ws://' (for example, in the case of a client trying to connect with the wrong address), I am not informed of any error.
The only signal I get in this case from the websocket is the stateChanged that takes the value ConnectingState.
Is there a way to ensure, given a specific timeout, the websocket will emit a signal error ?
Thank you by advance!
Ni.Sumi last edited by Ni.Sumi
You can set
bool QAbstractSocket::isValid() conston the given address provided. you can also get error signal from the websocket, if it is not valid address.
void QAbstractSocket::error(QAbstractSocket::SocketError socketError). check here .
But , the isvlaid() is not very efficient like in your case WS:// instead of WSS://. Because to my knowledge isValid() says true to any address , if it is inform of address/standard way of address. In your cases, I prefer to use Regular Expression before connection to socket.