How does HTTP Protocol work?
HTTP is a request-response protocol that allows users to communicate data. Persistent connection and Non-persistent connection are parts of HTTP.
Non-Persistent Connection
non-persistence HTTP came with HTTP 1.0 now. It is outdated.
Round Trip Time (RTT) is the time spent sending a packet to the server and receiving back it.
For example, suppose the server wants to get ten javascript files when loading a webpage. Then ten different requests must be initialized to get these files.
Persistent Connection
- TCP connections kept open after transactions are complete are called persistent connections. Persistent alive across transactions until either the client or the server decides to close them.
- It is the idea of using a single TCP connection to send and receive multiple HTTP requests, as oppos instead of
- There are two persistence HTTP. They with tunnelling and without tunnelling persistence.
- HTTP 1.1 usually comes with tunnelling persistence.
Example use case1:
Run and Monitor this on the Wireshark-loopback traffic capture interface.
TCP start standard TCP handshake.
The above image shows how to Send the request and get the response
So when the client sends keep-alive, the server sends a Reset packet(RST). (because the client is trying to connect with the server after the server closes the connection).
Example use case2:
Checking what happens if we send another request just after receiving the response.
Now you can see the client is sending an ACK to the response. The client sends the request. Server ACK it. The server sends the answer, and then Client ACk it.
So after we send another request same happens as a cycle.
Additionally, you can see there are no FIN flags here. Because here, we keep talking to the backend, so the backend does not try to close the connection. That is what Persistent connection means.
References
https://www.youtube.com/watch?v=Yf06faA5-JY&t=994s&ab_channel=KrishDinesh