TCP session control
A TCP session consists of 3 stages which make it connection-oriented and reliable protocol:
- Session Starting
- Data Transmission
- Session Ending
Before a web server can attend to the requests made by a client, TCP uses a 3-way handshake to establish a session between the web server and the web client.
The client sends a single SYN packet(synchronize) to the server. The purpose of this is to ask the server if it is available for connecting.
The server sends a single SYN/ACK packet(acknowledge). This step tells the client that the server is available to talk and wants a message.
The client sends a single ACK packet to the server. This step is the client telling the server: “ok, let’s talk”.
Now that the connection is established, the data can be transmitted. TCP also ensures that the data packets are successfully transmitted and reassembled in the correct order at the receiver side.
There is a 4-step procedure before the session is terminated.
The server sends the client a FIN packet which means “I am done, can you hear me?”
The receiver sends an ACK packet stating “Yes, I can hear you”.
When the client is done downloading the webpage, it sends a FIN packet to the server saying “I am done, can you hear me?”
The server responds with a final ACK, after which the session can be successfully closed.