TCP/IP Detailed learning note establishment and termination of--TCP connection

Source: Internet
Author: User
Tags ack

1. Basic Concepts

Since TCP is a connection-oriented protocol, you must first establish a connection between the two parties before sending the data, and then we discuss the process of establishing the connection.

2. Establishing a TCP connection

As shown in the following:
1. First the requester sends a SYN segment with a serial number of 1 (indicating that the party has a starting sequence number of 1), at which time the data carried is 0 because the connection is not yet successful, and the front sender also tells the receiver that it can receive the largest segment of the packet MSS
2. After receiving the SYN segment, also give the other side back to a SYN side, tell the other party its serial number is 5 and carry to the other side of the ACK, but also tell the other party it can receive the maximum message segment MSS
3. The request side after receiving the other party carries the ACK SYN also sends an ACK to the other side, at this time the request party to establish with the other side establishes the contact, so at this time is the data segment can carry the data, this TCP three handshake to complete, by the TCP connection two ends can communicate

注意点:当一端建立连接时,所发送的SYN,也包含了此端的一个初始序号,的俩端的初始序号分别为1和5,此初始序号是由复杂算法随机产生的

Termination of the 2.TCP connection

As shown
1. First terminate the end to issue a fin end, the sequence number of the paragraph is 2. When received by the receiving end, send it an ACK and a fin with an ACK, when the sender receives this segment, the end of the receiver sends a confirmation, the connection is terminated

注意点:为啥终止连接要4次挥手,主要原因是,建立连接后数据是双向传递的,所以必须得把俩端的数据流动都给关掉,则每一端都得发一个自己的FIN以及一个确认收到对方FIN的ack,所以终止连接得4次挥手
3.TCP Connection Setup Timeout

Sometimes the receiver host failure, when the sender to send a TCP connection request, in the case of the other side can not receive, the sender will not be unlimited to send the request, but according to the time-out period to the request of indefinite, of course, the timeout time is also the longest time limit, generally 75S more than this time, The sending side will discard the connection

4. Maximum message length

The maximum message length, also known as MSS, indicates the maximum data segment length that TCP can transmit to each other, and in the previous way, when the connection is established, the SYN that is sent contains the MSS, the general size is 1024

5.TCP half-off

TCP provides a connection at one end after it is sent, still can receive the opposite data, just can't send the data, we can control the application to completely close with the semi-close, call Close (), the implementation is completely closed, call shutdown () implementation is what we say half close, Semi-closing is not commonly used in most cases

6.time_wait status

The TIME_WAIT state is also known as the 2MSL wait state, and the MSL is the maximum lifetime of a TCP segment, and the reason for this state is primarily to prevent late message segments from being received

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

TCP/IP Detailed learning note establishment and termination of--TCP connection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.