Palpitations in a nest against keepalive

What are the pros and cons for implementing your own heartbeat and setting a β€œfeat” for a socket?

I read somewhere that keepalive can sometimes fail, and the connection will still be closed (depending on the network structure). Another thing is that your own heartbeat can determine if the application is responding (not just the socket).

My main goal is to provide all this: to keep the connection alive, even though the data is not being sent (apart from the possible beating), quickly detect a loss of connection on both sides, and detect the reaction of the application.

I already implemented a simple heartbeat at both ends, and it works great, however, I wonder if I could replace it with the keepalive function.

+5
source share
1 answer

One problem with TCP that is built into the keepalive function is that it is not always easy to configure. For example, on Linux there are various options for setsockop () (for example, TCP_KEEPIDLE, TCP_KEEPCNT and TCP_KEEPINTVL), which you can use to set the keepalive behavior to what you want, but in other OSs these behaviors are not easily adjusted, at least not programmatically . Therefore, if you want your keepalive behavior to be portable for different operating systems and constantly monitor them, switching your own heartbeat usually happens.

, , heartbeat/no-op ( , keepalive ), keepalive, "" keepalive, TCP. keepalive ( keepalive Linux).

+3

All Articles