TCP/IP three handshake four waves

TCP transport connection

In the process of establishing a TCP connection, the following three problems should be solved:
(1) To enable each party to know the existence of both parties.
(2) To allow the two parties to negotiate some parameters (such as the maximum window value, whether to use the window expansion option and timestamp option, and quality of service, etc.).
(3) Ability to allocate transport entity resources (such as cache size, items in the connection table, etc.).

Connection establishment, data transfer and connection release

A: Client B: Server

A actively opens the connection, and B passively opens the connection.

1. The TCP server process of B first creates the transmission control block TCB, and prepares to receive the connection request of the client process. The server process is in the LISTEN state, waiting for connection requests from the client process.

2. A's TCP client process creates a transmission control module TCB, and then sends a request to connect a message segment to B. At this time, the header synchronization bit SYN=1, and an initial sequence number seq = x is selected at the same time. TCP stipulates that the SYN segment (that is, the report of SYN=1)

text) cannot carry data, but consumes a sequence number. At this point, the TCP client process enters SYN-SENT (synchronization has been sent)

condition.

3. After B receives the connection request segment, if it agrees to establish a connection, it sends an acknowledgement to A. In the acknowledgment segment, both the SYN bit and the ACK bit should be set to 1, the acknowledgment number ack = x+1, and its own sequence number seq = y. This segment also cannot carry

data, but also consumes a sequence number. At this time, the TCP server process enters the SYN-RCVD (synchronized received) state.

4. After the TCP client process receives the confirmation from B, it must also give confirmation to B. The ACK of the confirmation segment is set to 1, the confirmation number ack = y+1, and its own sequence number seq = x+1. The standard of TCP stipulates that the ACK segment can carry data. but if

If no data is carried, the sequence number is not consumed. In this case, the sequence number of the next data segment is still seq=x+1. At this time, the TCP connection has been established, and A enters the ESTABLISHED (connection established) state.

The above connection establishment process is called a three-way handshake

TCP connection release

1. The application process of A first sends a connection release segment to its TCP, stops sending data again, and actively closes the TCP connection. A sets the termination control bit FIN in the header of the connection release segment to 1, and its sequence number seq = u, which is equal to the previously transmitted

The sequence number of the last byte of the data is incremented by 1. At this time, A enters the FIN-WAIT-1 (termination wait 1) state and waits for B's confirmation. (The FIN segment will consume a sequence number even if it does not carry data)

2. B sends a confirmation request after receiving the connection release segment. The confirmation number is ack = u+1, and the sequence number of this segment is v, which is equal to the last byte of the data that B has transmitted before. The sequence number is incremented by 1. Then B goes into CLOSE-

WAIT (wait for shutdown) state. The TCP server process should notify the high-level application process at this time, so the connection from A to B is released. At this time, the TCP connection is half -close, that is, A has no data.

To send, but if B sends data, A still needs to receive. That is to say, the connection from B to A is not closed, and this state may last for a period of time.

3. After A receives the confirmation from B, it enters the FIN-WAIT-2 (termination state 2) state and waits for the connection release segment sent by B.

4. If B has no data to send to A, its application process notifies TCP to release the connection. At this time, the connection release segment sent by B must have FIN=1. Now assume that the sequence number of B is w (in the half-closed state B may send some more numbers

according to). B must also repeat the last sent acknowledgment number ack=u+1. At this time, B enters the LAST-ACK (last acknowledgment) state and waits for A's acknowledgment.

5. After A receives B's connection release segment, it must send an acknowledgement. Set ACK to 1 in the confirmation segment, the confirmation number ack=w+1, and its own sequence number seq=u+1 (according to the TCP standard, the previously sent FIN segment should be deleted

consumes a serial number). Then enter the TIME-WAIT (time waiting) state. Note that the TCP connection has not been released yet. A must pass the time 2MSL set by the time-wait timer (TIME-WAIT timer) before A enters the

into the CLOSED state. The time MSL is called the longest segment lifetime.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325944945&siteId=291194637