Why tcp connect termination need 4-way-handshake?

After googling a lot, I recognized that the four-way is actually two pairs of two-way handshakes.

If termination is a REAL four-way actions, the 2 and 3 indeed can be set 1 at the same packet.

But this a two-phase work: the first phase (i.e. the first two-way handshake) is :

Client ------FIN-----> Server

Client <-----ACK------ Server

At this moment the client has been in FIN_WAIT_2 state waiting for a FIN from Server. As a bidirectional and full-duplex protocol, at present one direction has break down, no more data would be sent, but receiving still work, client has to wait for the other "half-duplex" to be terminated.

While the FIN from the Server was sent to Client, then Client response a ACK to terminate the connection.

Concluding note: the 2 and 3 can not merge into one package, because they belong to different states. But, if server has no more data or no data at all to be sent when received the FIN from client, it's ok to merge 2 and 3 in one package.

References:

  1. http://www.tcpipguide.com/free/t_TCPConnectionTermination-2.htm
  2. http://www.tcpipguide.com/free/t_TCPConnectionEstablishmentProcessTheThreeWayHandsh-3.htm
  3. http://www.tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF-2.htm

I think of course the 2 and 3 can merge technically, but not flexible enough as not atomic.
The first FIN1 C to S means and only means: I would close on my way of communication. The first ACK1 S to C means a response to FIN1. OK, I know your channel is disconnected but for my S(server) way connection, I'm not sure yet. Maybe my receiving buffer is not fully handled yet. The time I need is uncertain. Thus 2 and 3 are not appropriate to merge. Only the server would have right to decide when his way of connection can be disconnected.


From Wikipedia - "It is also possible to terminate the connection by a 3-way handshake, when host A sends a FIN and host B replies with a FIN & ACK (merely combines 2 steps into one) and host A replies with an ACK.[14]"

Source:

Wikipedia - https://en.wikipedia.org/wiki/Transmission_Control_Protocol

[14] - Tanenbaum, Andrew S. (2003-03-17). Computer Networks (Fourth ed.). Prentice Hall. ISBN 0-13-066102-3.

Tags:

Tcp