HTTP three-way handshake & #160; establish a connection and 4-way handshake disconnect, handshake disconnect

Source: Internet
Author: User

HTTP three-way handshake to establish a connection and four-way handshake to disconnect, handshake to disconnect

Three-way handshake to establish A connection the first handshake: host A sends A packet with syn = 1 and generates A data packet with seq number = 1234567 to the server. Host B is known as SYN = 1 and A requires online connection; the second handshake: after receiving the request, host B needs to confirm the online information and send ack number = (seq + 1 of host A), syn = 1, ack = 1, generate A packet with seq = 7654321 for the third handshake: After receiving the packet, host A checks whether the ack number is correct, that is, the seq number + 1 sent for the first time, and whether the ack is 1. If yes, host A will send ack number = (seq + 1 of host B), ack = 1 again. After host B receives the message, confirm that the seq value is set to ack = 1, and the connection is established successfully. Four handshakes closed: Because the TCP connection is full-duplex, each direction must be closed separately. This principle is that when one party completes its data sending task, it can send a FIN to terminate the sending channel in this direction. Receiving a FIN only means that there is no data flow between the two parties. a tcp connection can still send data after receiving a FIN. First, the party that closes the service will take the initiative to close the service, and the other party will passively close the service.
(1) Client A sends a fin to disable data transmission from client A to server B (packet segment 4 ).
(2) When server B receives the FIN, it sends back an ACK and confirms that the serial number is 1 (packet segment 5 ). Like SYN, a FIN occupies a sequence number.
(3) server B Closes the connection with client A and sends A FIN to Client A (packet segment 6 ). (4) Client A sends back the ACK message for confirmation, and sets the confirmation sequence number to receive the serial number plus 1 (packet segment 7 ). Question 1: Why is the three-way handshake while the four-way handshake when the connection is closed? This is because when the SOCKET in the LISTEN status of the server receives a connection request from the SYN packet, it can reply to ACK and SYN (SYN plays a synchronous role) it is sent in a message. However, when the connection is closed, when the other party receives the FIN Message notification, it only indicates that the other party has no data to send to you; but not all your data may have been sent to the other party, therefore, you may not close the SOCKET immediately, that is, you may need to send some data to the other party, and then send the FIN message to the other party to indicate that you agree to close the connection now, therefore, the ACK messages and FIN messages are sent separately in most cases. HTTP Request Response common status code 100 ~ 199: the request is successfully received, and the client is required to submit the next request to complete the processing.
200 ~ 299: indicates that the request is successfully received and the entire process has been completed. Common 200
300 ~ 399: to complete the request, the customer needs to further refine the request. For example, the requested resource has been moved to a new address, commonly used 302 (meaning you request me, I want you to find someone else), 307 and 304 (I don't give you this resource, cache by yourself)
400 ~ 499: client requests are incorrect. Commonly Used 404 (meaning that the requested resources are not in the web server) 403 (the server rejects access and has insufficient permissions) 500 ~ 599: Server errors, usually 500

Related Article

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.