How to implement TCP / IP heartbeat on 2500+ sockets?

I currently have an asynchronous application for TCP / IP C # WinForms sockets, which is a server application. The application stores persistent sockets for clients. I would like to implement a heartbeat package to detect semi-open connections.

I initially thought about creating a loop and sending a heartbeat to my entire socket collection every xx number of seconds. However, I think that would be bad for performance.

I think I need to somehow shake the heartbeat and send several hundred sockets at once. Does anyone have experience / methods / implementations to effectively accomplish this?

+4
source share
1 answer

I do this (for more sockets) by simply tracking how long ago I last talked (or heard) about a particular socket. During the interval I ping for a certain age. Assuming the sockets are connecting / disconnecting / exchanging evenly, this gives me a pretty even distribution. In addition, you can always limit ping to a finite number of sockets per iteration: since you keep track of the latest information, those that you do not receive will still be eligible next time.

+4
source

All Articles