Transport Layer 8 - TCP transport connection management

EDITORIAL: This article is for "computer network seventh edition," the study notes

1-- transport layer Transport Layer Protocol Overview

2-- Transport Layer UDP User Datagram Protocol

The transport layer 3-- transmission control protocol TCP Overview

4 Transport layer - TCP reliable transport of works

Transport layer 5 - TCP packet header format segment

6 transport layer - TCP achieve reliable transmission

Transport Layer 7 - TCP flow control and congestion control

Transport Layer 8 - TCP transport connection management

TCP is a connection-oriented protocol. Transport connection There are three stages: establishing a connection, data transmission and connection release. TCP uses client-server mode to establish a connection. Initiate the application process to establish connection is called the client, while passively waiting for the application process to establish connection is called the server.

1. TCP connection establishment

TCP connection establishment called the handshake, the handshake between the client and the server need to exchange three TCP segments, also called three-way handshake packets.

5d36b730af99d71230

Figure:

  • A customer is assumed, B is a server, the first TCP ends are closed, and then open the active A, B passive open;

  • A beginning, B's TCP server to create a Transmission Control Block TCB, ready to accept the connection request of the client process. The service is in LISTEN state, waiting for client connection requests;

  • A TCB also create a module, intended to establish a TCP connection when, transmits a connection request packet to the section B, this time the first sync bit SYN = 1, while selecting an initial sequence number seq = x. TCP provisions, SYN segment does not carry data, but consumes a number, then the client process into a state of SYN-SENT (synchronous sent) a;

  • A B receives the connection request packet segments, if you agree to establish a connection, it sends an acknowledgment to A. Provided SYN = 1, ACK = 1, an acknowledgment number ack = x + 1, and sets the initial sequence number seq = y. This segment does not carry data but consume a serial number. At this time into the TCP server (received synchronization) state SYN-RCVD;

  • After the confirmation process receives TCP client B, but also sends an acknowledgment to B. ACK = 1, seq = x + 1, ack = y + 1. At this time, the ACK segment may carry data, but does not carry data is not consumed if the next sequence number of a segment number is still seq = x + 1. At this time, TCP connection has been established, and the client process enters state to ESTABLISHED (connection established) of;

  • A B After confirmation of receipt, but also into the ESTABLISHED state.

Why should send A final confirmation of it?

这是防止已失效的连接请求报文段突然又传送到了B而引发错误。

失效的连接请求:A第一次先发送了一个请求,但是丢失了,于是A再发送一个连接请求,重新建立连接,发送数据并释放连接。

但是有可能出现异常情况,即A发送的连接请求并没有丢失,而是滞留了在网络中。如果在传输数据完成之后,这个请求又发到B,B误以为A还要发送数据,因此发送确认报文,但是A没有运输需求,因此不予理睬。如果没有最后一次确认,B一直等待A的确认,这样会造成的浪费。

采用三报文握手,如果B没有收到A的确认,则可以知道A没有建立连接的需求,就可以避免上述这种情况。

2. TCP的连接释放

5d36c06f25e4685687

如图:

  • A和B目前都处于ESTABLISHED状态,A的应用进程向其TCP发出连接释放报文段,并停止发送数据,主动关闭TCP连接。此时,FIN=1,seq=u,u等于前面已发送的最后一个字节的序号加1。这时A进入到FIN-WAIT-1(终止等待1)状态,等待B的确认。FIN报文段即使不携带数据,也要消耗一个序号;

  • B收到释放连接后立即发出确认,此时,ACK=1,确认号是ack=u+1,序号seq=v,v等于B前面所有已传送数据的最后一个字节的序号加1。B进入到CLOSE-WAIT(关闭等待)状态,TCP服务器进程向高层应用进程告知,此时A到B的连接已经释放,TCP连接处于半关闭状态。但是,B到A这个方向的连接尚未关闭;

  • A收到B的确认后,就进入到FIN-WAIT2(终止等待2)的状态,等待B发送连接释放报文段;

  • 若B已经没有数据需要发送,则应用进程通知TCP释放连接,这时B发送的报文段:FIN=1,ACK=1,seq=w(可能后面又发送了一些数据),ack=u+1,并且这个报文消耗一个序号。B进入到LAST-ACK(最后确认)的状态,等待A的确认;

  • A收到B的确认后,必须对此发送确认报文。该报文中:ACK=1,seq=u+1,ack=w+1。然后进入到TIME-WAIT(时间等待)状态。

  • At this time, the TCP connection is not fully released, we must wait timer set after 2MSL, A CLOSED state before entering the elapsed time. MSL time called the maximum segment lifetime.

So why wait 2MSL it?

  1. A guarantee last transmitted ACK segment to reach B. Because the message may be lost, so B will retransmit the last acknowledgment segment, A re-send the confirmation message, and restart the timer until the A, B can enter the normal state to CLOSED;

  2. Prevent the above-mentioned "has failed connection request packet." During this time, the connection request message may disappear in the network.

In addition, B than A first into the CLOSED state.

Guess you like

Origin www.cnblogs.com/anzhengyu/p/11232813.html