KeepAlive is a built-in function of TCP which, if enabled for one end of a socket, will:
Send “empty” packets from the KeepAlive-enabled socket end to the other socket end whenever no data has been sent for a specified period of time.
Declare that a socket connection is dead (and thus disconnect the socket) if the other end of the socket does not respond to the “empty” packets within a specified period of time.
KeepAlive Technical Details:
Enabling KeepAlive for one end of a socket, will automatically send an “empty” packet across the socket (from the enabled end to the other end) whenever the enabled end detects that the socket has been idle for a given period of time (where “idle” means “no data has been sent”). Such a packet is often referred to as a probe.
An “empty” packet is in fact an ACK of an old packet number.
Upon receiving such an ACK, the receiving end will send an ACK with the current (expected) packet number.
These ACK’s do not affect, and are not visible to, the end user of the socket. They can only be seen using a packet sniffer.
Enabling KeepAlive at one end of a socket does not enable it at the other end.
What Problems Can TCP KeepAlive Solve?
Enabling KeepAlive on a socket can help you to do either of these two very different things:
Keep an idle socket connection alive.
Detect whether the computer at the other end of a socket is alive.
Examples of these are, respectively:
Stop a router from dropping the socket connection because the router thinks the connection has been idle for too long.
Detect whether the machine on the other end of a socket is still alive even though it hasn’t sent you any data for a long period of time.
Tags: what is KeepAlive, what is tcp keepalive, keep an idle socket connection alive, keep an idle socket alive, detect whether the computer at the other end of a socket is alive, detect whether a socket is alive, keep a socket connection alive, keepalive, socket, TCP, Transmission Control Protocol, C++, C