[TCP] handshake reason / TIME_WAIT role

Why establish a TCP connection requires three-way handshake?

The reason: In response to repeated delays array of problems existing in the network

example:

Assuming that the client sends a connection request packet segment is not lost in the network, but a network node in long stay, resulting in delays to reach the server. This in itself is a message that has failed connection, but the connection to the server after receiving the message, mistaken for a client to initiate a new connection, and then sends an acknowledgment segment to the client. At this time, because there is no three-way handshake connection, the client does not confirm the message on the server to respond, we will not send data to server, server to think that the connection has been established, has waited in vain for client data, so this server part of the network resources are wasted.

Why breaks the TCP connection needs to be four-way handshake?

Since a TCP connection is a full-duplex network protocol, allows simultaneous communication between the parties simultaneously transmits and receives data, in both directions also allows the transceiver connection is closed independently to avoid client data has been sent, the connection is closed to send a FIN server, and there are sent to the server where the client data is not completed transmission. Therefore, the need for close the TCP connection four-way handshake, each connected to a closing direction needs FIN and ACK two way handshake.

Meaning TIME_WAIT state

 

In the TCP connection, when the FIN passive close connection party (FIG client) transmits a packet arrives, the passive connection is closed one sends ACK acknowledgment message, and enters a TIME_WAIT state, and waits 2MSL period (MSL: maximum segment life). There are two reasons to do so:

  1. Passive close the connection party (server in the figure) does not receive the acknowledgment packet ACK over a period of time, it resends the FIN packet, thus closing one of the active connections need to stay in the waiting state to process the other party to send the FIN data pack. Otherwise he would respond with a RST packet to the passive party to close the connection, so that the other side somehow.

  2. In TIME_WAIT state, it does not allow the application and before the client (the client's ip and port numbers unchanged) to establish a new communication connection on the current ip and port. So as to avoid a new connection is received before ip and port connections remaining in the same network packet. This is also the time to wait for the TIME_WAIT state is set to be the reason 2MSL to ensure that the current network connection in both directions have not yet received TCP packet has all but disappeared.

Transfer: https://www.cnblogs.com/zhoudayang/p/6012257.html

Guess you like

Origin www.cnblogs.com/itplay/p/11104409.html