TCP three-time handshake four-time wave

Source: Internet
Author: User
Tags connection reset

1.OSI Reference Model of computer network architecture

2.TCP/IP Architecture

Second, TCP three-time handshake

TCP (Transmission Control Protocol): Transmission Control Protocol.

TCP is the host-to-host layer of the Transmission Control Protocol, providing a reliable connection service, using three-time handshake to establish a connection.

There are 6 types of flag bits for TCP:

1.SYN (make connection)

     indicates the synchronization sequence number used to establish the connection. The SYN flag bit is used with the ACK flag bit, when the connection request is syn =1, ACK = 0; When the connection is responding, the syn =1, ACK = 1; the packet for this flag is often used for port scanning.

2.ACK (confirm)

     This flag indicates that the answer domain is valid, that is, the preceding TCP answer number will be included in the TCP packet ; There are two values: 0 and 1, and 1 indicates that the answer field is valid, and vice versa is 0.

3.PSH (transmit)

     This flag bit indicates the push operation. The so-called push operation means that the packet is delivered to the application immediately after it reaches the receiving end, rather than queued in the buffer;

4.FIN (end)

     Indicates that the sender has reached the end of the data, that is, the data transfer is complete, no data can be transmitted, the TCP packet sent the FIN flag bit, the connection will be disconnected.

5.RST (reset)

     This flag indicates a connection reset request. It is used to reset the connection that generated the error and is also used to reject the wrong and illegal packets.

6.URG (Emergency)

     This flag indicates that the TCP packet's emergency pointer field (which is coming soon) is valid to ensure that the TCP connection is not interrupted. and urge the middle-tier device to process this data as soon as possible.

TCP is connection-oriented, and you must first establish a connection between the two parties in either direction before the other party sends the data. In the TCP/IP protocol, the TCP protocol provides a reliable connection service, which is initialized by a three-time handshake. The purpose of the three-time handshake is to synchronize the serial number and confirmation number of both parties and Exchange TCP window size information.

1. First handshake: Establish a connection.

The client sends the connection request message, syn=1, randomly generates SEQ=X, the client enters the Syn_send state, waits for the server to confirm.

2. Second handshake: The server receives a SYN message segment.

The server receives the client's SYN message segment, needs to confirm this SYN segment, set ack=x+1, and also send the SYN request Syn=1, serial number seq=y; the server sends all of the above information to a message segment (that is, syn+ack) and sends it to the client. The server enters the SYN_RECV state at this time.

3. Third handshake: The client receives the server's Syn+ack message segment.

The serial number seq=y+1, sends the ACK message segment to the server, after this message segment sends completes, the client and the server side both enters the established state, completes the TCP three times handshake.

Third, TCP four wave

1. First Breakup

The host 1 sets the SEQ and ACK, sends the FIN message segment to host 2, at which time the host 1 enters the fin_wait_1 state, indicating that the host 1 has no data to be sent to host 2.

2. Second Breakup

  • Host 2 received the Host 1 sent fin message segment, to the host 1 back to a ACK message segment, ACK=seq+ 1; Host 1 into the fin_wait_2 state; Host 2 tells host 1 that I "agree" with your request to close.

    3. Third Breakup

    Host 2 sends the FIN segment to host 1, requests to close the connection, and the host 2 enters the CLOSE_WAIT state;

    4. The fourth time to break up

  • Host 1 received a message segment sent by host 2 FIN , sent to host 2 ACK message segment, and then host 1 into TIME_WAIT the state, host 2 received a host 1 of the ACK message segment, the connection is closed, at this time, the host 1 wait for 2MSL still did not receive a reply, This proves that the server side has shut down properly, so the host 1 can also shut down the connection.
  • TCP three-time handshake four-time wave

    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.