Get/Check Windows Keepalive event
-
I want to use "Keepalive" message to check if the net connection are good or not. That is, If there are no ACKs returned from the remote for the 'Keepalive' meeages I sent, I will assume the link may broken. But how I got the event, or what APIs I should call to check it?
-
@diverger What are you talking about? Some win32 API messages? Networking?
"check if the net connection are good or not" - what kind of connection do you mean?
If it is a network connection then take a look at http://doc.qt.io/qt-5/qtnetwork-index.html -
@jsulm I use QTcpSocket to communicate with a remote host. The connection may sometimes lost due to some reasons, such as cable un-plugged, or cable broken. So I try to enable 'Keepalive' socket options to make the app aware this. IMHO, when the OS send some keepalive probes and receive no ACKs, then it should think the connection is lost. But how can my app know this? Does Qt have some slots to receive this event information? Or I should call some Qt's functions or Windows API to query this information?
-
@diverger Since you're using QTcpSocket you can check its documentation:
http://doc.qt.io/qt-5/qabstractsocket.html#disconnected
and
http://doc.qt.io/qt-5/qabstractsocket.html#error-1
and
http://doc.qt.io/qt-5/qabstractsocket.html#stateChanged -
@diverger said in Get/Check Windows Keepalive event:
OS send some keepalive probes
There is no such thing. But you will be notified if your socket gets disconnected. Just connect slots to the signals I mentioned before.
-
@diverger said in Get/Check Windows Keepalive event:
OS's keepalive probes
What are "OS's keepalive probes"? There is no such thing to my knowledge.
If the connection is lost you will get disconnected signal and socket state will change. -
Hi
I never heard about that before. :)
Sounds pretty useful.
https://blogs.technet.microsoft.com/nettracer/2010/06/03/things-that-you-may-want-to-know-about-tcp-keepalives/ -
http://doc.qt.io/qt-5/qabstractsocket.html#SocketOption-enum
But bear in mind the keep-alive mechanism is low-level. You can't manipulate it, you'll just get your connection dropped if an
ACK
package times out.