Search code examples
tcptcp-keepalive

What is the typical usage of TCP keepalive?


Consider a scenario where exists one server and multiple clients. And each client creates TCP connections to interact with the server. There are three usages of TCP alive:

  1. Server-side keepalive: The server sends TCP keepalive to make sure that the client is alive. If the client is dead, the server closes the TCP connection to the client.
  2. Client-side keepalive: Clients sends TCP keepalive to prevent the server from closing the TCP connection to the client.
  3. Both-side keepalive: Both server and clients send TCP keepalive as described in 1 and 2.

Which of the above usages of TCP keepalive are typical?


Solution

  • Server-side keepalive: The server sends TCP keepalive to make sure that the client is alive. If the client is dead, the server closes the TCP connection to the client.

    If the client is dead, the server gets a 'connection reset' error, after which it should close the connection.

    Client-side keepalive: Clients sends TCP keepalive to prevent the server from closing the TCP connection to the client.

    No. Client sends keepalive so that if the server is dead, the client will get a 'connection reset' error, after which it should close the connection.

    Both-side keepalive

    Both sides are capable of getting a 'connection reset' due to keepalive failure, as above.

    Whuch of the above usages is typical?

    Any of them, or none. If a peer is sending regularly it doesn't really need keepalive as well. It is therefore often of more use to a server than a client.