Keep-alives were added to HTTP to basically reduce the significant overhead of rapidly creating and closing socket connections for each new request. The following is a summary of how it works within HTTP 1.0 and 1.1:
HTTP 1.0 The HTTP 1.0 specification does not really delve into how Keep-Alive should work. Basically, browsers that support Keep-Alive appended an additional header to the request as [edited for clarity] explained below:
When the server processes the request and generates a response, it also adds a header to the response:
Connection: Keep-Alive
When this is done, the socket connection is not closed as before, but kept open after sending the response. When the client sends another request, it reuses the same connection. The connection will continue to be reused until either the client or the server decides that the conversation is over, and one of them drops the connection.
The above explanation comes from here. But I don't understand one thing
When this is done, the socket connection is not closed as before, but kept open after sending the response.
As I understand we just send tcp packets to make requests and responses, how this socket connection
helps and how does it work? We still have to send packets, but how can it somehow establish the persistent connection? It seems so unreal.