Look TCP

Definition 1

TCP (Transmission Connect Protocol), there are oriented transport protocol connection. And by checking the sequence number, retransmission control, connection management controls for reliability and transmission window.

Two part format

  1. Source port number (Source Port): indicates the port number of sending end, the field length is 16.
  2. Destination port number (Destination Port): port number represented by the receiving end, the field length is 16.
  3. Sequence number (Sequence Number): 32 length field. Refers to the position of the transmission data, TCP sequence numbers can be achieved with the data ordered data retransmission and the like.
  4. Acknowledgment number (Number): 32-bit length field. If found by the acknowledgment number data before a sequence number is correctly received.
  5. Offset data (Data Offset): a length field is 4 bits, can be considered as the length of the TCP header.
  6. Reserved (Reserved): left extended use, field length of 4.
  7. Control bit (Control Flag)

 

    1) Emergency URG (Urgent Flag)

    When URG equal to 1, indicates that the urgent pointer field is valid. It tells that there is this segment of the urgent data to be transmitted (the equivalent of high-priority data) as soon as possible, rather than to deliver in accordance with the original line up order. URG When set to 1, the transmission application process to tell the sender's TCP urgent data to transmit, then put the insertion sending TCP urgent data to the front of the newspaper data segment, the data after the data of the emergency still the normal data, this time to the urgent pointer with header to use.

    2) acknowledgment ACK (Acknowledgement Flag)

    The bit ACK = 1, the acknowledgment number field is valid. TCP includes the addition to the initial connection establishment connection SYN Bauchi than when the bits are set to 1;

    3) Push PSH (Push Flag)

    PSH = 1, TCP PSH can use the push operation, and immediately create a segment sent. The receiver receives PSH = segment 1, it is as soon as possible (ie "push" forward) to accept delivery of the application process, rather than wait until the entire cache are filled and then delivered up;

    4) the reset RST (Reset Flag)

    When RST = 1, show that serious errors occur TCP connections, you must be strong disconnect. RST is set to reject a further illegal or reject a segment open a connection. RST also known reconstruction position or reset position;

    5) Synchronization SYN (Synchronization Flag)

    When used to synchronize the serial connection is established. When SYN = 1 and ACK = 1, indicates that this is a connection request packet segments. If the consent of the other connector, it should be in a segment in response to the SYN = 1 and ACK = 1.

    6) termination FIN (Fin Flag)

    For releasing a connection, when the FIN = 1, the sender of secondary data segment has been transmitted, and for the release of the transport connection;

       8. Window size (Window Size): 16-bit length field, TCP flow control is performed by the sliding window concept.

       9. Inspection and (Checksum)

3 Look at the three-way handshake with the four waving

 

 

1. The three-way handshake

  The first handshake: connection is established, the client sends syn packets (syn = x) to the server, and enters the SYN_SENT state, waiting for the server to confirm; the SYN: synchronization sequence number (Synchronize Sequence Numbers).

  Second handshake: server receives syn packets, must confirm the customer SYN (ack = x + 1), while themselves sends a SYN packet (syn = 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 = x + 1), this packet is sent, the client and server into the ESTABLISHED (TCP connection succeeds) state, complete the three handshake.

 

2. Four waving

  First wave: The client process issues a connection release message and stops sending data. Releasing the data packet header, FIN = 1, the sequence number seq = u (equal to the sequence number of the last byte previously transmitted from the data plus 1) In this case, the client enters the FIN-WAIT-1 (termination waiting 1) state. TCP provisions, FIN segment, if not carrying data, but also consume a serial number.

  第二次挥手:服务器收到连接释放报文,发出确认报文,ACK=1,ack=u+1,并且带上自己的序列号seq=v,此时,服务端就进入了CLOSE-WAIT(关闭等待)状态。TCP服务器通知高层的应用进程,客户端向服务器的方向就释放了,这时候处于半关闭状态,即客户端已经没有数据要发送了,但是服务器若发送数据,客户端依然要接受。这个状态还要持续一段时间,也就是整个CLOSE-WAIT状态持续的时间。客户端收到服务器的确认请求后,此时,客户端就进入FIN-WAIT-2(终止等待2)状态,等待服务器发送连接释放报文(在这之前还需要接受服务器发送的最后的数据)。

  第三次挥手:服务器将最后的数据发送完毕后,就向客户端发送连接释放报文,FIN=1,ack=u+1,由于在半关闭状态,服务器很可能又发送了一些数据,假定此时的序列号为seq=w,此时,服务器就进入了LAST-ACK(最后确认)状态,等待客户端的确认。

  第四次挥手:客户端收到服务器的连接释放报文后,必须发出确认,ACK=1,ack=w+1,而自己的序列号是seq=u+1,此时,客户端就进入了TIME-WAIT(时间等待)状态。注意此时TCP连接还没有释放,必须经过2MSL(最长报文段寿命)的时间后,当客户端撤销相应的TCB后,才进入CLOSED状态。服务器只要收到了客户端发出的确认,立即进入CLOSED状态。同样,撤销TCB后,就结束了这次的TCP连接。可以看到,服务器结束TCP连接的时间要比客户端早一些。

 

Guess you like

Origin www.cnblogs.com/tianliang94/p/11223214.html