The handshake wave and state transition of TCP are the basis of many network problems. Discuss and record relevant issues here.
First, this diagram outlines the process of TCP connection and disconnection:
Note Several of these states:
LISTEN, Syn-send, SYN-RCVD, established, Fin-wait-1, close-wait, Fin_wait-2, Last-ack, time-wait, CLOSE.
It seems that there are some cases of sending fin packets at the same time, but easy to confuse, so I think can be ignored.
Below, there are some notable issues:
1. Why the connection is 3 times the handshake, and the time of disconnection is 4 times.
Answer: The ACK and SYN can be returned together because the connection was initiated. While disconnecting, the receiver may also have data not issued, so fin can not be issued directly, can only send an ACK first.
2.3 Handshake, what happens if the last Ack is lost.
Answer: The receiver waits for an ACK timeout and then re-sends the previous syn+ack, and times out doubles to avoid network congestion. The connection is not yet established. If the sender sends a data message, it receives the RST packet returned by the receiving party.
3. Why Time_wait is 2MSL.
Answer:
1. In order to prevent the last ACK from being lost. If the ACK is lost, the receiver re-emits fin, at which point the sender needs to resend the ACK. You can avoid repeated time-out retransmission by the receiver.
2. Prevent the appearance of lost Duplicatie + incarnation connection. Lost duplicate refers to a recurring packet that has been delayed due to network congestion, and incarnation connection refers to a new connection that is identical to the original socket pair. When both are present, the data is likely to be confusing. Waiting for 2MSL, you can let the lost duplicate package disappear in the network.
Content reference:
http://blog.csdn.net/whuslei/article/details/6667471
Http://blog.sina.com.cn/s/blog_5d2054d9010189l2.html
Discussion on the related problems of four wave waving of TCP three-time handshake