有没有什么办法preserve消息为了在SignalR永久连接? [英] Is there any way to preserve message order in a SignalR Persistent Connection?

查看:172
本文介绍了有没有什么办法preserve消息为了在SignalR永久连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种情况是在SignalR(V1.1.2从的NuGet)一个JavaScript客户端在ASP.NET MVC4项目永久连接。一旦连接我连续发送多条消息从客户机到服务器。在服务器上我OnReceived覆盖函数从在这将导致消息被接收的无序的多个线程同时,因为它成为一个比赛,看看哪一个第一次打我锁调用。从服务器向客户端发送的消息显示,为了尽管这可能只是运气交付。

The situation is a single javascript client on a SignalR (v1.1.2 from NuGet) persistent connection in an ASP.NET MVC4 project. Once connected I send multiple messages in a row from the client to the server. On the server my OnReceived override function gets called from multiple threads at the same time which causes the messages to be received out of order since it becomes a race to see which one hits my lock first. Messages sent from the server to the client appear to be delivered in order though that could just be luck.

有在两个方向对单个客户端消息令的任何期望呢?有没有办法,我失踪,其中列出了持久连接作出的保证的任何文档?

Is there any expectation of message order in either direction for an individual client? Is there any documentation that I'm missing that lists the guarantees made by the persistent connection?

我需要做什么特别,以确保服务器到客户端的邮件都保存在顺序呢?大多数我的发送从持久连接,所以我目前只是打电话IConnection.Send而忽略返回的任务以外来异步。

Do I need to do anything special to ensure server to client messages are kept in order as well? A majority of my sends come asynchronously from outside of the persistent connection so I'm currently just calling IConnection.Send and ignoring the returned Task.

推荐答案

简单的回答是否定的。当您从服务器发送信息给客户,事情总会解决的。然而,从客户端发送到服务器,即传出排队客户端到服务器调用的唯一运输的W​​ebSockets。

The quick answer is no. When you send messages from server to client, things will always be in order. Sending from client to server however, the only transport that queues outgoing client to server calls is websockets.

通过努力才能从客户端发送到服务器,因为没有办法知道发送完成时,当你的运气了持久连接。在另一方面集线器返回递延(在C#中的任务),它可以让你伺候发送再次发送之前完成。

With persistent connections you're out of luck when trying to order sends from client to server as there's no way to know when the send is complete. Hubs on the other hand return a deferred (and task in C#), which lets you wait on the send to complete before sending again.

这篇关于有没有什么办法preserve消息为了在SignalR永久连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆