Why tcp connect termination need 4-way-handshake?

后端 未结 5 1263
感动是毒
感动是毒 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:16

    If this is observed from the angle of coding, it is more reasonable to have 4 way than 3 way although both are possible ways for use.

    When a connection is to be terminated by one side, there are multiple possibilities or states that the peer may have. At least one is normal, one is on transmitting or receiving, one is in disconnected state somehow all of a sudden before this initiation.

    The way of termination should take at least above three into consideration for they all have high probabilities to happen in real life.

    So it becomes more natural to find out why based on above. If the peer is in offline state, then things are quite easy for client to infer the peer state by delving into the packet content captured in the procedure since the first ack msg could not be received from peer. But if the two messages are combined together, then it becomes much difficult for the client to know why the peer does not respond because not only offline state could lead to the packet missing but also the various exceptions in the procedure of processing in server side could make this happen. Not to mention the client needs to wait large amount of time until timeout. With the additional 1 message, the two problems could become more easier to handle from client side.

    The reason for it looks like coding because the information contained in the message is just like the log of code.

提交回复
热议问题