Can SignalR handle missed messages?

前端 未结 1 2037
囚心锁ツ
囚心锁ツ 2020-12-31 11:55

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

相关标签:
1条回答
  • 2020-12-31 12:08

    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.

    0 讨论(0)
提交回复
热议问题