Illustrates a TCP-IP protocol

This article TCP-IP protocol to sort through knowledge map. TCP communication process includes three steps of: establishing a TCP connection channel, data transmission, channel disconnect the TCP connection. As shown in FIG. 1, a schematic diagram of the TCP communication process.


 

Figure 1 TCP three-way handshake fourth wave

1 mainly includes three parts: connection establishment, data transfer, is disconnected.

1) establish a TCP connection is very simple, you can establish a connection through the three-way handshake.

2) After the connection is established, begin transmitting data. TCP data transmission involves a lot of concepts: retransmission timeout, fast retransmission, flow control, congestion control, and so on.

3) disconnection procedures are very simple, four-way handshake is completed by a disconnected process.

Three-way handshake to establish a connection:

The first handshake: a client sends syn packets (seq = x) to the server, and enters SYN_SEND state, waiting for the server to confirm;

Second handshake: server receives syn packets, must confirm the customer SYN (ack = x + 1), while themselves sends a SYN packet (seq = y), i.e., SYN + ACK packet, then the server enters a state SYN_RECV;

Third handshake: the client receives the SYN + ACK packet to the server, the server sends an acknowledgment packet ACK (ack = y + 1), this packet is sent, the client and server into the ESTABLISHED state, complete the three-way handshake.

Bag handshake does not include the transfer of data, after three-way handshake is completed, the client and server before the official start transferring data. Ideally, TCP connection, once established, before any party in the communication of the two parties take the initiative to close the connection, TCP connection will be kept down.

Data transmission process:

a. timeout retransmission

Retransmission timeout mechanism is used to ensure the reliability of the TCP transport. Each time a packet transmission, transmission of data packets has seq number, the receiving terminal receives the data, confirmation will reply ack, seq denotes a number of data has been received. The sender after sending a certain seq pack, wait for some time, if no reply is received corresponding ack, it will assume packet loss will retransmit the packet.

b. fast retransmit

Receiving data packets party found to have lost. Ack packets will be sent to tell the sender retransmission of lost packets. If continuous transmission packet receive the same reference numerals ack end, fast retransmit client is triggered. Compare timeout retransmission and fast retransmission, retransmission timeout can be found at the sending end is Shadeng timeout, then trigger a retransmission; and it is fast retransmit receiving end of the initiative to tell the sender data is not received, the sender then retransmits the trigger.

c. Flow Control

这里主要说TCP滑动窗流量控制。TCP头里有一个字段叫Window,又叫Advertised-Window,这个字段是接收端告诉发送端自己还有多少缓冲区可以接收数据。于是发送端就可以根据这个接收端的处理能力来发送数据,而不会导致接收端处理不过来。 滑动窗可以是提高TCP传输效率的一种机制。

d.拥塞控制

滑动窗用来做流量控制。流量控制只关注发送端和接受端自身的状况,而没有考虑整个网络的通信情况。拥塞控制,则是基于整个网络来考虑的。考虑一下这样的场景:某一时刻网络上的延时突然增加,那么,TCP对这个事做出的应对只有重传数据,但是,重传会导致网络的负担更重,于是会导致更大的延迟以及更多的丢包,于是,这个情况就会进入恶性循环被不断地放大。试想一下,如果一个网络内有成千上万的TCP连接都这么行事,那么马上就会形成“网络风暴”,TCP这个协议就会拖垮整个网络。为此,TCP引入了拥塞控制策略。拥塞策略算法主要包括:慢启动,拥塞避免,拥塞发生,快速恢复。

四次握手断开连接:

第一次挥手:主动关闭方发送一个FIN,用来关闭主动方到被动关闭方的数据传送,也就是主动关闭方告诉被动关闭方:我已经不会再给你发数据了(当然,在fin包之前发送出去的数据,如果没有收到对应的ack确认报文,主动关闭方依然会重发这些数据),但此时主动关闭方还可以接受数据。

第二次挥手:被动关闭方收到FIN包后,发送一个ACK给对方,确认序号为收到序号+1(与SYN相同,一个FIN占用一个序号)。

第三次挥手:被动关闭方发送一个FIN,用来关闭被动关闭方到主动关闭方的数据传送,也就是告诉主动关闭方,我的数据也发送完了,不会再给你发数据了。

第四次挥手:主动关闭方收到FIN后,发送一个ACK给被动关闭方,确认序号为收到序号+1,至此,完成四次挥手。

Guess you like

Origin www.cnblogs.com/linhaozuishuai/p/11956315.html