System learning TCP/IP protocol (ii) ------ connection establishment and Closure

Source: Internet
Author: User

System learning TCP/IP protocol (ii) ------ establish and disable TCP reliable transmission is first established on the establishment and closure of reliable connections, which includes the following points: TCP three-way handshake established connection TCP half-closed TCP status change TCP server listening and processing design TCP three-way handshake established connection TCP to both parties confirm the establishment of the connection, the three-way handshake policy is designed, the three-way handshake process is as follows: 1) the requester sends a SYN segment to indicate the port of the server to which the customer intends to connect and the initial serial number (ISN ). 2) the server sends back the SYN packet segment containing the server's initial serial number as the response. At the same time, set the serial number to the customer's ISN plus 1 to confirm the customer's SYN packet segment. A syn occupies a sequence number. 3) the customer must set the validation serial number to ISN plus 1 of the server to confirm the SYN packet segment of the server. For example: Why is the three-way handshake? For this problem, a classic rule in network programming may give some tips: if someone tells you that the success is successful, it must be successful. If you don't tell you that the success is not necessarily unsuccessful. Therefore, if two handshakes are designed, the connection may be established successfully after the first ack message is sent by the connected party, but the message is lost, because the active connection party does not receive the ack message, it will think that the connection fails and may discard the connection or start a new connection. However, the connected party will always listen to the connection that it mistakenly believes is successful. If the three-way handshake is used, any failure of the first two handshakes will cause both parties to be In the unconnected State. If the third handshake fails, only the connection provider is in the successful state, but the initiator is the active one, data will be sent through the connection shortly after the connection, so that further fault tolerance can be implemented using this mechanism. The tcpdump tool clearly shows the three-way handshake process, first in host B (itbu_qa17) open tcpdump monitoring/usr/local/sbin/tcpdump port 80 and host 10.19.14.1 and then host A (10.19.14.1) telnet to host B. The tcpdump monitoring result is as follows: when TCP is half-closed, TCP provides the ability of one end of the connection to receive data from the other end after sending the connection. Therefore, when the connection is closed, both parties need to initiate a message to close the connection, as shown in the following figure: Why is it designed to be semi-closed? Designed to be semi-closed, data does not need to be sent. You only need to receive data, and the data has been sent by initiating a unilateral request closure. If you do not need to disable the service, you have to establish two connections. The tcpdump tool clearly shows the three-way handshake process. host a (10.19.14.1) telnet to host B, and then in host B (itbu_qa17) open tcpdump monitoring/usr/local/sbin/tcpdump port 80 and host 10.19.14.1 and then host A closes telnet. The tcpdump monitoring result is as follows: the status change of the TCP connection goes through some States from the new connection to the established connection to the closed connection. These statuses are very important in analyzing the problem. The status change panorama is as follows: the status change sequence is shown in the following figure: TCP server listening and processing design: TCP server is generally designed as the process listening port after the connection is established, when a new connection request arrives at the server, the server accepts the request and calls a new process to process the new customer request. Take telnet as an example. Use netstat to check that the server listening status is LISTEN, as shown in. When a client telnet, the listening process starts to process another process, as shown in:

 

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.