Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

TCP protocol of transport layer

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

1. About TCP

TCP is a transmission control protocol that works at the transport layer. Features:

1 > provide connection-oriented services

2 > TCP connections are peer-to-peer

3 > provide reliable interactive services

4 > provide full-duplex communication

5 > oriented to byte stream

Transport connection Management of 2.TCP

TCP is a connection-oriented protocol, and transport connections are used to transmit TCP messages. There are three stages of transport connection: connection establishment, data transfer and connection release.

(1) connection establishment of TCP (three-way handshake)

The process of establishing a connection is shown in the figure:

Suppose host An is running a TCP client program and B is running a TCP service program. The initial TCP processes on both sides are in the CLOSED state. The boxes below the host in the figure are the states of the TCP process. An actively opens the connection and B passively opens the connection.

The TCP server process of 1 > B first creates the transmission control block TCB, ready to accept the connection request of the client process, and then the server is in the LISTEN state, waiting for the connection request of the client. If so, respond immediately.

The TCP client process of An also creates the transmission control block TCB, and then sends the connection request message segment to B. at this time, the synchronization bit SYN=1 in the header, while selecting an initial sequence number seq=x, stipulates that the SYN message segment cannot carry data, but consumes a sequence number, and then the TCP client process enters the SYN-SENT (synchronization sent) state.

2 > after B receives the connection request message segment, if it agrees to connect, send a confirmation to A. When confirming, set both SYN and ACK to 1, confirm the number ack=x+1, and choose a sequence number seq=y for yourself. This message segment also does not carry data, but also consumes a sequence number. At this point, the TCP server process enters the SYN-RCVD state.

After receiving the confirmation from B, the TCP client process of 3 > A will also send the confirmation to B. Set the ACK to 1, the confirmation number ack=y+1, and your own serial number seq=x+1;x+1;ACK message segment can carry data, but if you do not carry the data, the serial number will not be consumed. In this case, the serial number of the next data message segment is still seq=x+1, and the TCP connection has been established. An enters the ESTABLISHED (connection established) state.

After B receives the confirmation from A, An also enters the ESTABLISHED state.

(2) connection release of TCP (four waves)

1 > A the application process first sends a connection release message segment to its TCP, stops sending data, and actively closes the TCP connection. A sets the termination control bit FIN of the header of the message to 1, and the sequence number is seq=u, which is equal to the sequence number of the last byte of the previously transmitted data plus 1, then An enters the FIN-WAIT-1 state and waits for the confirmation of B. It is stipulated that the FIN message segment does not carry data, but a sequence number is consumed.

2 > B will issue a confirmation after receiving the connection release message, the confirmation number is ack=u+1, and its serial number is v. Equal to the sequence number of the last byte of previously transmitted data plus 1. Then B enters the CLOSE-WAIT state. The TCP server process should notify the high-level application process, so the connection from A to B is released. At this time, the TCP connection is half-closed, that is, A has no data to send to B, but if B sends data, A still receives it. The connection from B to An is not closed. This state may last for some time.

3 > An enters the FIN-WAIT-2 state after receiving the confirmation from B and waits for B to send out the release message segment of the connection.

B has no data to send to A, and its application process notifies TCP to release the connection. Then the message segment FIN=1 sent by B, assuming that the sequence number B repeats the last confirmation number ack=u+1, then B enters the LAST-ACK state and waits for the confirmation of A.

4 > A must confirm this after receiving the connection release message segment of B. Set ACK to 1, back to 1, back to 1, 1 to 1, to 1, and to 1, to 1. Then enter the TIME-WAIT state. Now that the TCP connection has not been released, A must wait for the time set by the timer to 2MSL before An enters the CLOSED state.

As long as B receives the confirmation from A, it enters the CLOSED state.

(3) TIME-WAIT-- time waiting status

Why set the time to wait for 2MSL?

1 > in order to ensure that the last ACK segment sent by A can reach B. This ACK message segment may be lost, so that B in the LAST-WAIT state cannot receive the confirmation of the sent FIN+ACK message segment. B will retransmit the FIN+ACK segment during the timeout, and A will receive the retransmitted segment within the 2MSL time. Then A retransmits a confirmation, restarts the timer, and finally An and B enter the CLOSED state normally. If A does not wait for a period of time in the TIME-WAIT state, but releases the connection immediately after sending the ACK message segment, the FIN+ACK message retransmitted by B cannot be received, and the acknowledgment will not be sent again, and B will not be able to enter the CLOSED state in the normal state.

2 > prevent invalid connection request message segments from appearing in this connection. An after sending the last ACK message segment, after the time 2MSL, all the message segments generated during the duration of this connection can disappear from the network. In this way, this old connection request segment does not appear in the next new link.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report