Server determines if HTTP is interrupted

Source: Internet
Author: User
In general, only send or recv is required, and if the result is zero, the line is dropped. 1. When the recv return value of 0 is a disconnect that indicates that the other party is already normal (MSDN said to be perfect).
2. When Recv returns to Socket_error, it indicates that the other party is disconnected, but may be disconnected (off-screen or end-of-client process). If you are worried about being blocked while reading, use Select (This is not a good idea) but, under a long connection, It is possible that there is no data exchange for a long time. At this point the heartbeat mechanism is needed, and TCP itself has a heartbeat mechanism. If you set a heartbeat, TCP will send your heartbeat (say 2 times) within a certain amount of time (for example, 3 seconds), and this information will not affect your own defined protocol. The so-called "Heartbeat" is the time to send a custom structure (heartbeat packet or heartbeat frame), let the other side know that they are "online." To ensure the validity of the link. The so-called heartbeat packet is the client sends a simple message to the server and tells it I'm still there. In general, the heartbeat packet is mainly used for long-connection keepalive and disconnection processing. In general application, the judgment time in 30-40 seconds is quite good. If the demand is high, it will be 6-9 seconds.

Server determines if HTTP is interrupted

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.