Detailed TCP three-way handshake and four wave

Three or four times TCP handshake problems often waving the interview the interviewer asked the

On the Internet, how to communicate with each other in different segments of the host, you need to use the TCP protocol;
TCP, connection-oriented service, must establish a connection before transmitting data, to be released after the completion of the data transfer connection. TCP is a reliable transport service, the use of three-way handshake to establish a connection.

First introduced to the format of the TCP packet
Detailed TCP three-way handshake and four wave
sequence number transmitted byte number for each end, the receiving end to facilitate correct recombinant.
Acknowledgment number for confirming the data sender.
Window size for explaining the number of local data segments may be received.

Flag
URG urgent pointer bit open 0 1 closed.
Without the cache submitted directly to each other.

PSH quickly passed to the receiving application layer open 0 1 closed
need to go through the cache, and a number of segments in attendance, sent directly to the application layer.

SYN synchronization bit serial connection establishment request flag
FIN disconnect request flag of the
ACK acknowledgment number bit
RST reconnect

Three-way handshake

The first handshake
client and server want to establish a connection, it sends a SYN to a server to the server, waiting for the server to confirm
the second handshake
TCP server receives a request message, make sure SYN packet, the connection if you agree, then the issue SYN + ACK packet.
the third handshake
after the client receives the server SYN + ACK packet, but also send a confirmation packet to the server ACK, this package has been sent, then the two sides can begin to communicate, and complete the three-way handshake.

Four waving

Since a TCP connection is full-duplex, so each direction must be shut down separately. The principle is that when one task completes its data transmission can send a FIN to terminate the connection direction. Receive a FIN only means that no data is flowing in this direction, a TCP connection can still send data after receiving a FIN. First off will be the one to perform active close, while the other performs a passive close.
The first wave
server sends FIN and ACK TCP segment position 1 to the client.
Second Wave
client returns ACK position 1 TCP segment to the server.
The third wave
client sends a FIN and ACK position of a TCP segment to the server.
In the process of TCP connection is disconnected, there is the concept of a semi-closed. TCP party (usually the client) may stop sending data, but can still receive data, referred to as half off.

Why three-way handshake to establish a connection from time to time, but always disconnect the fourth wave?
When the connection is closed, the server receives each other's FIN message, said the other no longer sends data, but also receive data, while he may not have all the data is sent to the other side, so to the other party after sending the data before sending FIN messages to each other to agree now to close the connection, therefore, ACK, and FIN usually sent separately, causing more than once.

Guess you like

Origin blog.51cto.com/14449798/2427331