UWP C# StreamSocket TCP Sending Heartbeat Message To Monitor Devices
Is there any common practice technique to send heartbeat message to monitor the client devices?
What I am doing currently is setup a tasktimer and polling each client device at one second interval and wait for client device's to acknowledge before incrementing the counter to poll the second device.
If there is no acknowledgement from a device, I will attempt again up to 3 tries.
Is this a good practice?
Please advise.
Thanks.
Solution 1:
TCP provides reliable, ordered, and error-checked delivery of a stream of octets (bytes) between applications running on hosts communicating via an IP network. Applications that do not require reliable data stream service may use the User Datagram Protocol (UDP), which provides a connectionless datagram service that emphasizes reduced latency over reliability. Ref: "wiki".
In general, if your server and clients work in:
- wired network instead of wireless network
- neither of them crashes
No need to implement a heartbeat.
While heartbeat/PING/keep-alive is absolute or only working way to check the connection. But how to implement a heartbeat is a good practice or best for you, depends on your use case, for example, how often the heartbeat is efficient for you? The possible reasons for the client lost connection.
More refences:
"Do I need to heartbeat to keep a TCP connection open?"
"Keep Alive TCP/IP connected sockets over the Internet - when? how? and how much?"
"TCP Dead link detection"