If we can recall from earlier, TCP sessions are a finite object.
Once sessions are completed,
they are closed in a manner so polite it would make
the British royal family proud.
Let's take a closer look at session termination.
Session termination is required to aid in
conserving network and system resources.
If sessions were never closed,
the server would have no idea what was acted and what wasn't.
So the server would have two choices.
Either keep the connection open,
which at some point would allow for no further connections.
Actually,
this may not be bad if it would curtail my wife's online shopping addiction.
The second option would be for the server to arbitrarily
decide which connections to prune,
which could be problematic if it closed an active session.
Now the second option does happen as there are mechanisms in
place that allow for this type of a scenario.
For example, you're just about to place that order online and boom,
you encounter a power outage, and your internet is cut.
At some point,
the server will decide that the connection is no longer
valid and close the connection ungracefully.
To terminate a session gracefully,
it's similar to a three‑way handshake with one more step.
So essentially, it's a four‑way handshake.
A graceful session termination works through the use of ACK and FIN.
Let's drop to a diagram and cover our last section of TCP for this module.
In this scenario,
the computer of 192.168.1.1 is done communicating
with the server of 192.168.1.100.
As our super cool robot image has been successfully downloaded,
the server of 192.168.1.100 sends a FIN ACK to the computer of 192.168.1.1.
The computer of 192.168.1.1 responds with an ACK,
acknowledging the request to close the connection.
The computer of 192.168.1.1 then replies with a FIN ACK of its own saying,
yep, let's close this connection.
The web server of 192.168.1.100 then responds with an ACK, and then the connection is successfully closed.