Please Whitelist This Site?
I know everyone hates ads. But please understand that I am providing premium content for free that takes hundreds of hours of time to research and write. I don't want to go to a pay-only model like some sites, but when more and more people block ads, I end up working for free. And I have a family to support, just like you. :)
If you like The TCP/IP Guide, please consider the download version. It's priced very economically and you can read all of it in a convenient format without ads.
If you want to use this site for free, I'd be grateful if you could add the site to the whitelist for Adblock. To do so, just open the Adblock menu and select "Disable on tcpipguide.com". Or go to the Tools menu and select "Adblock Plus Preferences...". Then click "Add Filter..." at the bottom, and add this string: "@@||tcpipguide.com^$document". Then just click OK.
Thanks for your understanding!
Sincerely, Charles Kozierok
Author and Publisher, The TCP/IP Guide
|
NOTE: Using software to mass-download the site degrades the server and is prohibited. If you want to read The TCP/IP Guide offline, please consider licensing it. Thank you.
|
|
|
|
TCP Connection Termination
(Page 2 of 4)
Normal Connection Termination
In the normal case, each side terminates
its end of the connection by sending a special message with the FIN
(finish) bit set. This message, sometimes called a FIN, serves
as a connection termination request to the other device, while also
possibly carrying data like a regular segment. The device receiving
the FIN responds with an acknowledgment to the FIN to
indicate that it was received. The connection as a whole is not considered
terminated until both sides have finished the shut down procedure by
sending a FIN and receiving an ACK.
Thus, termination isn't a three-way
handshake like establishment: it is a pair of two-way handshakes. The
states that the two devices in the connection move through during a
normal connection shutdown are different because the device initiating
the shutdown must behave differently than the one that receives the
termination request. In particular, the TCP on the device receiving
the initial termination request must inform its application process
and wait for a signal that the process is ready to proceed. The initiating
device doesn't need to do this, since the application is what started
the ball rolling in the first place.
Key Concept: A TCP connection is normally terminating using a special procedure where each side independently closes its end of the link. It normally begins with one of the application processes signalling to its TCP layer that the session is no longer needed. That device sends a FIN message to tell the other device that it wants to end the connection, which is acknowledged. When the responding device is ready, it too sends a FIN that is acknowledged; after waiting a period of time for the ACK to be received, the session is closed. |
Table 154
describes in detail how the connection termination process works; the
progression of states and messages exchanged can also be seen in Figure 214.
The table is adapted from Table 151,
describing the TCP finite state machine, but shows what happens for
both the server and the client over time during connection shutdown.
Either device can initiate connection termination; in this example I
am assuming the client does it. Each row shows the state each device
begins in, what action it takes in that state and what state to which
it transitions. I have also shown the send and receive stages of both
of the steps for each of the client and servers close operations.
Table 154: TCP Connection Termination Procedure
Client
|
Server
|
Start
State
|
Action
|
Transitions
To State
|
Start
State
|
Action
|
Transitions
To State
|
ESTABLISHED
|
Client Close Step #1 Transmit:
The application using TCP signals that the connection is no longer needed.
The client TCP sends a segment with the FIN bit set to request
that the connection be closed.
|
FIN-WAIT-1
|
ESTABLISHED
|
At this stage the server is still
in normal operating mode.
|
|
FIN-WAIT-1
|
The client,
having sent a FIN, is waiting for it to both be acknowledged
and for the serve to send its own FIN. In this state the client
can still receive data from the server but will no longer accept data
from its local application to be sent to the server.
|
|
ESTABLISHED
|
Client Close
Step #1 Receive and Step #2 Transmit: The server receives the client's
FIN. It sends an ACK to acknowledge the FIN. The
server must wait for the application using it to be told the other end
is closing, so the application here can finish what it is doing.
|
CLOSE-WAIT
|
FIN-WAIT-1
|
Client Close Step #2 Receive:
The client receives the ACK for its FIN. It must now wait
for the server to close.
|
FIN-WAIT-2
|
CLOSE-WAIT
|
The server waits for the application
process on its end to signal that it is ready to close.
|
|
FIN-WAIT-2
|
The client
is waiting for the server's FIN.
|
|
CLOSE-WAIT
|
Server Close
Step #1 Transmit: The server's TCP receives notice from the local
application that it is done. The server sends its FIN to the
client.
|
LAST-ACK
|
FIN-WAIT-2
|
Server Close Step #1 Receive
and Step #2 Transmit: The client receives the server's FIN
and sends back an ACK.
|
TIME-WAIT
|
LAST-ACK
|
The server is waiting for an
ACK for the FIN it sent.
|
|
TIME-WAIT
|
The client
waits for a period of time equal to double the maximum segment life
(MSL) time, to ensure the ACK it sent was received.
|
|
LAST-ACK
|
Server Close
Step #2 Receive: The server receives the ACK to its FIN
and closes the connection.
|
CLOSED
|
TIME-WAIT
|
The timer expires after double
the MSL time.
|
CLOSED
|
CLOSED
|
The connection is closed on the
server's end.
|
|
CLOSED
|
The connection
is closed.
|
|
CLOSED
|
The connection
is closed.
|
|
Figure 214: TCP Connection Termination Procedure This diagram shows the conventional termination procedure for a TCP session, with one device initiating termination and the other responding. In this case the client initiates; it sends a FIN which is acknowledged by the server. The server waits for the server process to be ready to close and then sends its FIN, which is acknowledged by the client. The client waits for a period of time to ensure that its ACK is received, before proceeding to the CLOSED state.
|
If you find The TCP/IP Guide useful, please consider making a small Paypal donation to help the site, using one of the buttons below. You can also donate a custom amount using the far right button (not less than $1 please, or PayPal gets most/all of your money!) In lieu of a larger donation, you may wish to consider purchasing a download license of The TCP/IP Guide. Thanks for your support! |
|
|
Home -
Table Of Contents - Contact Us
The TCP/IP Guide (http://www.TCPIPGuide.com)
Version 3.0 - Version Date: September 20, 2005
© Copyright 2001-2005 Charles M. Kozierok. All Rights Reserved.
Not responsible for any loss resulting from the use of this site.
|