Java Socket parameters: keepalive

Source: Internet
Author: User

Keepalive is not a common TCP connection. When we connect to a client as a server, if keeplive is set to true, when the other party does not send any data, if the time exceeds one (depending on the system kernel parameter configuration), an ACK detection packet will be sent to the other party to check whether the TCP/IP connection between the two parties is valid (the other party may break the network ). If this parameter is not set, when the client goes down, the server will never know that the client is down and will still save the invalid connection.
You can also use this parameter on the client. The client socket sends a packet to the server every two hours. This packet does not have any other function, just to check whether the server is still active. If the server does not respond to this packet, the client socket will send another packet after about 11 minutes. If the server does not respond within 12 minutes, the client socket will be closed. If you disable the socket option, the client socket may not be closed for a long time if the server is invalid.
Although keepalive has few benefits, many developers advocate controlling timeout settings and dead sockets in higher-level application code. At the same time, remember that keepalive does not allow you to specify a value for the end point of the probe socket (endpoint. Therefore, it is recommended that developers use anotherA better solution is to modify the socket option of timeout settings..
To put it bluntly: this parameter is actually useless for applications at the application layer. You can use the application layer to understand the status of the server or client and decide whether to continue to maintain the socket.

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.