TCP three handshake and four times the whole process of waving and why three times handshake answer

Source: Internet
Author: User
Tags ack connection reset

TCP three handshake and four wave of the whole process


TCP is the host to the host Layer Transmission Control Protocol, providing a reliable connection service, with three handshake confirmation to establish a connection:


Bit code is the TCP flag bit, there are 6 kinds of representations:

SYN (Synchronous establish connection)

ACK (acknowledgement indicates response, confirmation)

PSH (push indicates data transfer)

FIN (finish close connection)

RST (reset indicates connection reset)

URG (Urgent emergency pointer field value valid)


three times handshake:


First handshake: The client sends the SYN packet (SYN=X) to the server, and enters the Syn_send state, waiting for the server to confirm;

Second handshake: The server received the SYN packet, must confirm the customer's SYN (ACK=X+1), but also send a SYN packet (syn=y), that is Syn+ack packet, at this time the server into the SYN_RECV state;

Third handshake: The client receives the server Syn+ack packet, sends the confirmation packet ack (ACK=Y+1) to the server, this packet sends completes, the client and the server enters established state, completes three times handshake.

Handshake process in the packet is not included in the data, three times after the handshake, the client and the server began to transfer data officially. Ideally, once a TCP connection is established, the TCP connection is maintained until either side of the communication actively closes the connection.

Confirmation Number: Its value is equal to the sender's send ordinal number +1 (the next serial number that the receiver expects to receive).

four times waving:

Similar to a "three handshake" to establish a connection, disconnecting a TCP connection requires "four waves".

Wave for the first time: The active shutdown sends a FIN, which is used to turn off the data transmission of the active side to the passive shutdown, i.e. the active shutdown tells the passive shutdown: I will not send you the data again (of course, the data sent before the FIN packet, if you do not receive the corresponding ACK acknowledgement message, The active shutdown will still be able to send the data back, but the active shutdown can accept the data at this time.

Second wave: The passive closing party receives the fin packet, sends an ACK to each other, confirms that the serial number is received ordinal +1 (same as Syn, a fin occupies a serial number).
Third wave: Passive shutdown to send a fin, to close the passive closed to the active shutdown data transmission, that is, to tell the active shutdown, my data is sent out, will not send you data.
Fourth wave: The active closed party received the fin, send an ACK to the passive closed side, confirm serial number +1 received, so, four times to complete the wave.


TCP's four wave-waving process (in brief): Active shutdown direction passive closed to send you no further information, the passive closed party to receive the active shutdown of the message segment to confirm; passive shutdown direction active shutdown side send me no more information about sending you data. The active closing party confirms the passive closing party again.

The entire process of TCP three handshake and four wave waving is shown below:


TCP's three-time handshake process. Why do you shake hands three times, if you use two times to shake hands?

A: The process of establishing a connection is to take advantage of the client server model, assuming host A is the client and Host B is the server side.

(1) TCP three times handshake process: Host A to B send a connection request, Host B to receive the host a message segment confirmation; Host A again confirms Host B confirmation.

(2) The use of three times handshake is to prevent the failure of the connection request message segment suddenly transmitted to host B, resulting in errors. Invalid connection request message segment refers to: Host a issued a connection request did not receive the confirmation of Host B, so after a period of time, host a again send the connection request to Host B, and the establishment of a successful, sequentially completed data transmission. Considering such a special case, host a first sent a connection request is not lost, but because the network node caused the delay to reach Host B, Host B thought it was a new connection initiated by host A, so host B agreed to connect and sent back to host a confirmation, but at this time host a would not bother, Host B has been waiting for host A to send data, causing host B to waste resources.

(3) The use of two handshake is not possible, the reason is said above the failure of the connection request of the special circumstances, so the use of three handshake just good, two may appear ineffective, four times or more times are not necessary, but complex.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.