简体   繁体   English

什么是确保客户端已接收到来自Signalr Server点的消息的好方法

[英]What is a good way to ensure that a message from a signalr Server point has been received by the client

I have a ASP.NET server app that uses SignalR. 我有一个使用SignalR的ASP.NET服务器应用程序。 I have an HTML5 client. 我有一个HTML5客户端。 The server sends a small byte array (around 12k) JPEG to my client, which receives and displays the image in an IMG element. 服务器向我的客户端发送一个小字节数组(约12k)JPEG,该客户端接收并在IMG元素中显示图像。

The frequency of the data sent to the client(s) is erratic, and I am concerned about overload. 发送到客户端的数据的频率不稳定,我担心过载。 At the moment I use timer control to relay messages from server at regular intervals. 目前,我使用计时器控制来定期中继来自服务器的消息。 For desktop browsers using a dedicated broadband connection everything works smoothly, however if I use a mobile device browser the mobile can take longer to load an image for whatever reason (like poor internet connection and/or low power supply on the battery). 对于使用专用宽带连接的台式机浏览器,一切都可以正常运行,但是,如果我使用移动设备浏览器,则无论出于何种原因(例如互联网连接不良和/或电池电量不足),移动设备都可能需要更长的时间来加载图像。

Ideally, I would like my client(s) to send an acknowledgement to my server to 'say' the image has been loaded OK and I am ready to receive the next one. 理想情况下,我希望我的客户端将确认发送到我的服务器,以“说”该图像已加载好,并且我准备接收下一个图像。 I could facilitate the received notification either through a signal client method or say an API call. 我可以通过信号客户端方法或说API调用来简化接收到的通知。

I am worried about 2 things: 我担心两件事:

  • Unnecessary overhead from headers (etc) from client to server call 客户端到服务器调用的标头(等)的不必要开销

  • Negating the benefits of using SignalR 否认使用SignalR的好处

I am strongly leaning to just relying on timers in server controls and increasing the 'timeout' for mobile devices but I am open to ideas. 我强烈希望仅依靠服务器控件中的计时器并增加移动设备的“超时”,但是我愿意接受想法。 Has anyone else encountered this type of scenario and if so have a different approach? 是否还有其他人遇到过这种情况?如果有,请采用其他方法?

Try the approach documented in this answer . 尝试此答案中记录的方法。

Summary: Assign each JPEG an ID. 摘要:为每个JPEG分配一个ID。 When the client is ready for the next image have it report the ID of the last image loaded so that the server knows which image to send next. 当客户端准备好下一幅图像时,它报告上一次加载的图像的ID,以便服务器知道接下来要发送的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM