Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can SignalR handle missed messages?

Tags:

signalr

Say my network connection drops for a few seconds and I miss some SignalR server-pushed messages.

When I regain network connectivity are the messages I missed lost? or does signalR handle them and push them out when I reconnect?

If it can't handle missed messages, then what is the recommended approach for ensuring consistency?

  • Periodically (2-3 mins) poll to check server-data?
  • Somehow detect loss of network on the client side and do an ajax call to get the data on network restoration?
  • something else?
like image 296
reach4thelasers Avatar asked Apr 23 '12 14:04

reach4thelasers


People also ask

Does SignalR guarantee delivery?

SignalR doesn't guarantee message delivery. Since SignalR doesn't block when you call client methods, you can invoke client methods very quickly as you've discovered. Unfortunately, the client might not always be ready to receive messages immediately once you send them, so SignalR has to buffer messages.

How long do SignalR connections stay open?

The default keepalive timeout period is currently 20 seconds. If your client code tries to call a Hub method while SignalR is in reconnecting mode, SignalR will try to send the command. Most of the time, such attempts will fail, but in some circumstances they might succeed.

Is SignalR UDP or TCP?

SignalR is more closely aligned to the UDP pattern of communication, and not TCP.

How do I send client specific messages using SignalR?

We change the BroadcastChartData() method to accept connectionId as an additional parameter. This way, we can find the client using the connectionId and send a message just to that client. Additionally, we add a new GetConnectionId() method, which returns the connectionId of the client.


1 Answers

Here are a couple of thoughts:

If you aren't sending a lot of messages per second, consider sending no data in the messages themselves. Instead, the message is just a "ping" to the clients telling them to go get the server data when they can. Combine that with a periodic poll, as you said, and you can be assured that you won't miss messages. They just might be delayed.

If you are sending a lot of messages quickly, how about adding a sequential ID to each one? Think of a SQL Identity column. Your clients would need to keep track of the most recent ID received. After a network reconnect, the client could ask for all messages since [Last ID]. If a message is received whose ID is not contiguous with the most recently received, you know that there was a disconnect and can ask the server for the missing information.

like image 149
MikeC Avatar answered Sep 21 '22 17:09

MikeC