- At first, the person for three times handshake and four waves this thing still sometimes forget, may not understand very deep, so today do it yourself to record this knowledge point, easy to see later. Summed up after the conclusion is still possible haha.
- Three-time handshake to establish a connection
- The first time: the client and server side are off at first. ①: When you want to establish a connection, the client first actively opens, then the server side is passive open.
②: The server first has to create the necessary PCB Transmission control block (refer to the socket programming, first to establish some of the information required by the server, including sockets, such as creating sockets, binding sockets,), and then enter the listen state, waiting for the client to connect themselves. The client also has to build its own PCB structure (create sockets).
③: The first connection begins: The client makes a connection request, sends a request message (SYN: Handshake signal =1,ack: Confirmation mechanism =0,seq: Connection sequence = random number x),
Client Status: Syn-sent (Sync sent)
- Second time: Consent to connect, send consent message (SYN: Handshake signal =1,ack: Confirmation mechanism =1,ack: Confirm signal =x+1,seq: Connect serial number = random number Y), here is a serial number Y, Server Status: Syn-rcvd (Sync received)
- Third: After the client receives a connection acknowledgement from the server, it must return the confirmation connection signal to the server (ACK: Acknowledgement mechanism =1, ACK: Confirmation signal =y+1, SEQ: Connection Sequence number = random number x+1 (based on the previous request signal plus 1))
Client Status: estab-lished (connection established). When the server receives the server status: estab-lished (Connection established)
Note: The meaning of the third handshake: in order to prevent the connection request message segment that has expired suddenly transmitted to B.
- four waves to release the connection
- First: The client first sends the connection release message segment (FIN: Terminating connection flag =1,SEQ: Serial number =x), fin=1 to the server to break up. Client Status: fin-wait-1 (terminating connection wait State 1)
- Second: Because the TCP connection is full duplex, the shutdown is also closed from both sides, and when the server receives the FIN=1 flag from the client , the server does not immediately send the find= to the client . 1 of the request to close the message, but first send a ack=1 response to the client , indicating: You request to close the request I have received, but I may still have the data is not completed transmission, you wait, wait for my data transfer is complete I will tell you; acknowledgment message (ACK: acknowledgement mechanism = 1,ack: Confirm signal =x+1,seq: Serial number =y)
Server Status: close-wait (Shutdown wait), so the client -to- server connection is released
Client Status: Fin-wait-2 (terminating connection wait state 2)
- The third time: server-side data transfer complete, no dynamic wash transmission, the server side of the release connection request (FIN: Terminating connection flag =1,ack: Confirmation mechanism =1,SEQ: Serial number =z,ack: Confirm Signal =x+1)
Server Status: Last-ack (last confirmed)
- Fourth time: Host1 received fin=1 , host1 or fear because of the network instability reasons, afraid host2 don't know he want to disconnect, so host2 send ack=1 confirmation information to confirm, set himself into time_ WAIT State and start the timer, if the HOST2 does not receive the ACK,HOST2-side TCP timer arrives, will ask Host1 to resend the ACK, when Host2 received an ACK, HOST2 disconnected When Host1 waits for 2MLS (twice times the maximum message lifetime), he knows that Host2 has received an ACK after receiving the HOST2 's retransmission request, so host1 closes his connection at this time. I think it's a very ingenious design.
TCP/IP three-time handshake and four-time let go