0
\$\begingroup\$

I am having client/server application and i want to detect if client is alive.

So i know that send() will return me null but it will not inform my server that client has been disconnected.

Way i came up is each N seconds send "Are you alive" message from server to client but is that good solution?

\$\endgroup\$
  • 2
    \$\begingroup\$ This is called a keepalive. Have you observed any problems with using this approach? \$\endgroup\$ – DMGregory Jan 14 at 4:39
  • \$\begingroup\$ No and i am doing it like that but somewhere i read it is not good idea to do it like that so wanted to ask what is other solution \$\endgroup\$ – Aleksa Ristic Jan 14 at 11:11
  • 1
    \$\begingroup\$ Who said it was not good, and why? We can solve a problem better if we know what problem it is we're solving. \$\endgroup\$ – DMGregory Jan 14 at 12:42
1
\$\begingroup\$

This is a good solution, since it allows both sides to know that their partner is alive.

Call it keepalive or hearbeat.

Added benefit, when done frequently (1/sec) you can monitor lag / ping.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.