Keepalive

TCP implementation MAY include "keepalive". If keepalive are included, the application MUST be able to turn them on or off for each TCP connection, and they MUST default to off.
The keepalive packets MUST only be sent when no data or acknowledgment packets have been received for the connection within a time period. This time period MUST be configurable and MUST default to no less than two hours. Keepalive interval is the duration between two successive keepalive retransmissions, if acknowledgment to the previous keepalive transmission is not received.
Keepalive retry is the number of retransmissions to be carried out before declaring that remote end is not available.

Why use keepalive?

Some server application might hang indefinitely if the client did not end the connection correctly. This will consume unnecessarily resources from the server.

Why some implementation of TCP does not include a keep-alive mechanism

1) It can cause good connections to break during temporary network failures;
2) Consume (unnecessary) network resources.
3) Some network charge money for bandwidth usages.

osischool.com

Embedding:
Do not change the code.