Three handshakes, four waves.

Source: Internet
Author: User

Characteristics of TCP

TCP provides a connection-oriented, reliable byte-stream service
In a TCP connection, only two parties communicate with each other. Broadcast and multicast cannot be used with TCP
TCP uses checksums, acknowledgements, and retransmission mechanisms to ensure reliable transmission
TCP Usage Cumulative acknowledgement
TCP uses the sliding window mechanism to achieve traffic control by dynamically changing the size of the window for congestion control
Three handshakes and four waves

The so-called three-time handshake (three-way handshake) means that when a TCP connection is established, the client and server are required to send a total of 3 packets. The purpose of the three-time handshake is to connect the server to the specified port, establish a TCP connection, and synchronize the serial number and confirmation number of both parties, exchanging TCP window size information. In socket programming, the client executes connect (). Will trigger a three-time handshake. * First handshake (syn=1, seq=x):
客户端发送一个 TCP 的 SYN 标志位置1的包,指明客户端打算连接的服务器的端口,以及初始序号 X,保存在包头的序列号(Sequence Number)字段里。发送完毕后,客户端进入 `SYN_SEND` 状态。
* Second handshake (syn=1, Ack=1, Seq=y, acknum=x+1):
服务器发回确认包(ACK)应答。即 SYN 标志位和 ACK 标志位均为1。服务器端选择自己 ISN 序列号,放到 Seq 域里,同时将确认序号(Acknowledgement Number)设置为客户的 ISN 加1,即X+1。 发送完毕后,服务器端进入 `SYN_RCVD` 状态。
* Third handshake (ack=1,acknum=y+1)
客户端再次发送确认包(ACK),SYN 标志位为0,ACK 标志位为1,并且把服务器发来 ACK 的序号字段+1,放在确定字段中发送给对方,并且在数据段放写ISN的+1发送完毕后,客户端进入 `ESTABLISHED` 状态,当服务器端接收到这个包时,也进入 `ESTABLISHED` 状态,TCP 握手结束。

The removal of TCP connections requires the sending of four packets, so called four waves (Four-way handshake), also known as the improved three-time handshake. Either the client or the server can initiate a wave gesture, and in socket programming, any party performs a close () operation to generate a wave. Wave for the first time (FIN=1,SEQ=X)

Assuming that the client wants to close the connection, the client sends a package with a FIN flag position of 1, indicating that no data can be sent, but can still accept the data.

After sending, the client enters the fin_wait_1 state.

Second Wave (ack=1,acknum=x+1)

The server-side confirms the client's FIN package, sends a confirmation packet, indicates that it has accepted the client's request to close the connection, but is not ready to close the connection.

After sending, the server side enters the close_wait state, the client receives this confirmation packet, enters the fin_wait_2 state, waits for the server side to close the connection.

Wave for the third time (fin=1,seq=y)

When the server is ready to close the connection, send the end connection request to the client, and the FIN is set to 1.

After sending, the server side enters the Last_ack state, waiting for the last ACK from the client.

Wave for the fourth time (ack=1,acknum=y+1)

The client receives a shutdown request from the server, sends a confirmation packet, and enters the time_wait state, waiting for an ACK packet that may appear to require retransmission.

After the server receives this acknowledgement package, it closes the connection and enters the CLOSED state.

The client waits for a fixed time (two maximum segment life cycle, 2msl,2 Maximum Segment Lifetime), does not receive the server side of the ACK, the server side has been properly shut down the connection, so he also closed the connection, into the CLOSED state.

Four-way-handshake

Three handshakes, four waves.

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.