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\$
3
  • 2
    \$\begingroup\$ This is called a keepalive. Have you observed any problems with using this approach? \$\endgroup\$ Commented Jan 14, 2019 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\$ Commented Jan 14, 2019 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\$ Commented Jan 14, 2019 at 12:42

1 Answer 1

3
\$\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\$
1
  • 1
    \$\begingroup\$ Another benefit is when you try to send a heartbeat message to the "dead" client it will cause a SocketError on your end, forcing it to close. Otherwise, it may hang for a very long time. \$\endgroup\$ Commented Oct 2, 2019 at 7:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.