[Socket] explanation and verification of time_wait status when the connection is disconnected:

Source: Internet
Author: User

 

Explanation and verification of time_wait status:

 

In TCP synchronous duplex disconnection, if there is no time-Wait Status, the ACK n + 1 is returned when the last fin N is sent and the active shutdown party receives the request. at this time, if the n + 1 package is not correctly met, the other party will remain in the last ack status, and the sender will not be in the tim_wait status, if the message is correctly sent, it exits, causing the recipient to wait. After time_wait is added, the value of time_wait itself also indicates the time when the package can survive on the network. the receiver can simply think that n + 1 packets are not received during this time.
If this disconnection fails, you need to resend the serial number of the fin n. At this time, the time_wait end also needs to change the status
The status of the fin to be sent next time.

For the socket connection with repeated connections: Imagine that without the time_wait, you have just exited the socket and the socket has not been disconnected for four times.
After that, you may quit in close_wait and then immediately connect and issue your ack. The consequence is very serious, and
The other party may think that you are still in the last four disconnections ..

First, verification fails. Verify the second one as follows: bind a sockaddr_in on the client and specify the port. When disconnected, connect again immediately.

[tnsmcc@localhost client]$ ./client.exe 127.0.0.1 9000fdsfdsfdsfdsfdsfds[tnsmcc@localhost client]$ ./client.exe 127.0.0.1 9000[tnsmcc@localhost client]$ ./client.exe 127.0.0.1 9000[tnsmcc@localhost client]$ ./client.exe 127.0.0.1 9000

At this time, the port is in

  1. 127.0.0.1: 9005 127.0.0.1: 9000 time_wait
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.