Heartbeat timeout

I’m using C# ServerEventClient on .NET 4.6.2 over 3G internet connection.
On some locations network is unhealthy and is dropping packets.
HeartbeatInterval is set to 10sec and IdleTimeout is 30sec (I have tried other values with same result).
Sometimes heartbeat hang for over 30sec and client reconnect immediately after that.
Becouse of this, clients are constantly beeing dropped/reconnected which invoke leave / join events to be fired.
Is there posibility to set heartbeat timeout which will couse heartbeat to abort and send new heartbeat?


The 2 heartbeat intervals you can set on ServerEventsFeature is HeartbeatInterval indicating how often clients should send heartbeats and IdleTimeout indicating how long before not receiving a heartbeat should the server consider the connection disconnected.

Thank you, but issue I’m having is different.
What is happening is that client sends heartbeat request but it does not receives answer for more than heartbeat interval and then instead of sending new heartbeat at regulr interval it waits for previous one to timeout. At that moment client sends new heartbeat and reconnects immediatelly.

Essentially I need something like HeartbeatTimeout which should on happening abort current Heartbeat http request and send new one.
IdleTimeout = 30 sec
HeartbeatInterval = 10 sec
HeartbeatTimeout = 5 sec

If client does not receive answer to heartbeat in 5 secs it should cancel current one and send a new one which if passess it would avoid leave/join/reconnect on server.

The heartbeat doesn’t use an interval, it only sends the next heartbeat after the previous one returns.

Yes, I am aware of that.

What I’m asking is new functionality if it makes sense, which is to implement http request abort on client side on defineable timeout and send new request.
On poor or busy edge/3g network packets are often lost and current concept where heartbeat requests are kind of “queued” is not resilient enough.


Feature requests should go on UserVoice so their demand can be measured and prioritized.

But this just sounds like you want to Dispose the current client and create a new client ServerEventClient connection.

Is it safe to do something like this?

serverEventsClient.HeartbeatRequestFilter += request =>
    new Thread(() =>

I’d look at using a Timer instead, not sure what the consequences of cancelling the Heartbeat WebRequest is though, never been tested.

Ok, thank you for very quck responses.
I will try testing this with timer.

1 Like