Tcp key point learning-disconnect

Source: Internet
Author: User
Article title: tcp key point learning-disconnect. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

The main part is the four handshakes:

In fact, from my perspective, the client and the server are not differentiated. either party can call a function such as close (or closesocket) to actively terminate a connection. Now let's talk about the normal situation. When the close function is called to disconnect a connection, the party that actively disconnects sends the FIN (finish packet) to the other party. With your previous experience, I think you should understand what I mean when I talk about FIN packets. That is, a packet segment with the FIN flag configured. FIN packets may also be appended with user data. if there is still data to be sent on this side, it is completely normal to attach the data to this FIN packet. Later, you will see that there are many additional packets, such as ACK packets. The principle we need to grasp is that TCP will certainly achieve the maximum efficiency as far as possible, so you can think of the optimization method, I think TCP will think.

When a passively closed party receives a FIN message, it sends an ACK confirmation message (you should be familiar with ACK ). Here is something to note, because TCP is Duplex, that is to say, you can imagine that a pair of TCP connections have two data paths. When sending a FIN message, it means that one end of the send FIN cannot send data, that is, one of the data paths is disabled. After an ACK is sent to the end of the passive disconnection, the application layer usually detects that the connection is about to be disconnected, and then the application layer calls close to close the connection.

I can tell you that once you call close (or closesocket), this end will send FIN packets. That is to say, the end of passive shutdown also sends FIN to the active shutdown end. Sometimes, the passive shutdown end will combine the ACK and FIN packets to send them together. After receiving the FIN, the active closing end also sends ACK, and then closes the entire connection (in fact, it is not completely closed, but the packet to be switched is completely sent), and the four handshakes are completed. As you can see, because the passive shutdown end may combine ACK and FIN for sending, this is not a strict four-way handshake-four packet segments.

In the previous article, I did not mention TCP status conversion. Here I am still wondering if I should take out the general figure. However, here I will only show the status conversion chart when the connection is disconnected, from:

Screen. width * 0.7) {this. resized = true; this. width = screen. width * 0.7; this. style. cursor = 'hand'; this. alt = 'click here to open new window \ nCTRL + Mouse wheel to zoom in/out';} "onclick =" if (! This. resized) {return true;} else {window. open ('http: // Linux.chinaitlab.com/UploadFiles_7565/200910/20091023093916959.png');} "height = 507 alt =" "src =" http://Linux.chinaitlab.com/UploadFiles_7565/200910/20091023093916959.png "width = 529 onload =" if (this. width> screen. width * 0.7) {this. resized = true; this. width = screen. width * 0.7; this. alt = 'click here to open new window \ nCTRL + Mouse wheel to zoom in/out';} "border = 0>

The following figure shows the windump information during normal shutdown:

14:00:38. 819856 IP cd-zhangmin.1748> 220.181.37.55.80: F (0) ack 1 win 65535

14:00:38. 863989 IP 220.181.37.55.80> cd-zhangmin.1748: F (0) ack 2 win 2920

14:00:38. 864412 IP cd-zhangmin.1748> 220.181.37.55.80:. ack 2 win 65535

[1] [2] Next page

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.