The three-time handshake of TCP/IP protocol and four waves

Source: Internet
Author: User

Outline

First, IP Header

Second, the TCP Header

三、三次 Handshake Process

四、四次 waving process

V. TCP finite state machine




First, IP Header

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/75/D4/wKioL1ZDLwvS35b_AAGEFzEBb5U655.jpg "title=" Ip-header.jpg "alt=" Wkiol1zdlwvs35b_aagefzebb5u655.jpg "/>




Second, the TCP Header

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/75/D6/wKiom1ZDLomj1_tBAAGQj_KH3GM142.jpg "title=" Tcp-header.jpg "style=" Float:none; "alt=" wkiom1zdlomj1_tbaagqj_kh3gm142.jpg "/>


三、三次 Handshake Process

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/75/D7/wKiom1ZDPeeT3XAYAAC8Wqo6oOA555.jpg "title=" 3.jpg " alt= "Wkiom1zdpeet3xayaac8wqo6ooa555.jpg"/>




Three-time handshake process details:

  • ① First handshake: The client sends a connection request packet to the server, and the flag bit SYN (Synchronous sequence number) is set to 1, resulting in a serial number of x=0

  • ② Second handshake: The server received a message from the client, by Syn=1 know the client requirements to establish online. The client sends a TCP message with a SYN and an ACK of 1, sets its own initial sequence number y=0, sets the acknowledgment sequence number (ACK) to the client's serial numbers plus 1, which is x+1 = 0+1=1

  • ③ Third handshake: The client receives the packet sent by the server and checks to see if the sequence number (ACK) is correct, that is, the first sent sequence number plus 1 (x+1=1). And whether the flag bit ACK is 1. If correct, the server sends a confirmation packet again, and the ACK flag bit is 1,syn flag bit 0. Confirm the serial number (ACK) =y+1=0+1=1, and send the serial number to x+1=1. After the client receives the confirmation sequence value and the ack=1, the connection is established successfully and the data can be transferred.


四、四次 waving process

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/75/D5/wKioL1ZDQFGxUKskAAEn0RXyPQk544.jpg "title=" 6.jpg " alt= "Wkiol1zdqfgxukskaaen0rxypqk544.jpg"/>

Four waves in the process of explanation:

  • ① First wave: The client sends a TCP packet to the server to shut down the client-to-server data transfer. Set the flag position fin and ACK to 1, sequence number x=1, confirm the serial number is Z=1

  • After the ② server receives fin, it sends back an ACK (flag bit ack=1), confirming that the sequence number is the received sequence number plus 1, which is x=x+1=2. Serial number is the confirmation number received =z

  • The ③ server shuts down the connection to the client and sends a fin. Flag bit fin and ACK set to 1, sequence number is Y=1, confirm serial number is x=2

  • After the ④ client receives the fin sent from the server side, it sends back the ACK acknowledgement (flag bit ack=1), confirming that the sequence number is the received sequence number plus 1, which is the y+1=2. Serial number is the confirmation number received x=2


PS: The four-time handshake is used to close an established TCP connection. Sometimes, if the host needs to close the connection as soon as possible (or the connection times out, the port or the host is unreachable), the RST (Reset) package is sent. Because the RST package is not a necessary part of a TCP connection, you can send only the RST package (that is, without an ACK tag).


Five, TCP finite state machine


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/75/D7/wKiom1ZDO7bRfIAEAADQJktuzS4509.png "title=" Tcpfsm.png "alt=" Wkiom1zdo7brfiaeaadqjktuzs4509.png "/>



    • ①closed (Client): Blocked, closed state, indicating that the host is not currently active or in transit connection


    • ②listen (server): A listening state indicating that the server is waiting for a new transport connection to enter


  • ③syn_sent (Client): Indicates that the host has issued a transport connection request, waiting for the other party to confirm


  • ④SYN_RCVD (Server): Indicates that the host has received a transport connection request but has not yet confirmed


  • ⑤established (Client,server): Transmission connection established, communication between the two sides into the normal data transmission status


  • ⑥fin wait 1 (Client): (active shutdown) The host has sent a close connection request, waiting for the other party to confirm


  • ⑦close WAIT (Server): (passive shutdown) received a close transfer connection request from the other party, and confirmed


  • ⑧fin wait 2 (Client): (active shutdown) The host has received an acknowledgement that the other side is shutting down the transport connection, waiting for the other to send off the transfer connection request


  • ⑨last ACK (Server): (passive shutdown) wait for the last one to close the transport connection acknowledgement and wait for all packets to disappear


  • ⑩time_wait (Client): Complete two-way transport connection shutdown, waiting for all packets to disappear


  • CLOSED (Server): Both sides try to close the transmission connection at the same time, waiting for the other party to confirm







This article is from the "Hello,linux" blog, make sure to keep this source http://soysauce93.blog.51cto.com/7589461/1711934

The three-time handshake of TCP/IP protocol and four waves

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.