[QtNetwork] How to identify dead connection
-
Hi! Is there an implemented method in Qt to check if the connection is working or not? I'm realised that if client losts internet connection, server doesn't get any information about it. Do I have to implement ping operation? Thx for the answer.
-
What do you use? QNAM or *Socket classes?
-
I'm using QTcpSocket and QTcpServer.
-
Look at
bq. void QAbstractSocket::stateChanged ( QAbstractSocket::SocketState socketState ) [signal]
-
I thought about that and it was the first thing I checked. It changes only when I close the app without disconnecting but it doesn't work when you e.g. plug out network cable.
-
It should work. As additional check you can add timeouts to your read/write waits (if you use them) and check after it for failure.
-
The "right" way is to implement your own keepalive mechanism for your protocol (or use reasonable defaults). Otherwise you could try enabling the TCP keepalive mechanism, or use QtMobility's QSystemNetworkInfo to get notifications when the status of the networking changes, as discussed in this thread: http://developer.qt.nokia.com/forums/viewthread/2420
-
I've decided to write my own keepalive service. Topic can be closed. Thanks for help :)
-
It does work, but it waits for a usually rather long time out.