Why tcp connect termination need 4-way-handshake?

后端 未结 5 1252
感动是毒
感动是毒 2021-02-03 23:30

When connection sets up, there is:

Client ------SYN-----> Server

Client <---ACK/SYN---- Server ----①

Client ------ACK-----> Ser

5条回答
  •  后悔当初
    2021-02-04 00:10

    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

提交回复
热议问题