【发布时间】:2013-05-15 18:24:37
【问题描述】:
我有一个self-hosted 应用程序,类似于一个场景,其中我有一个持续向组广播的方法(无论有人“加入”与否)。比如:
var aTimer = new System.Timers.Timer(2000);
aTimer.Elapsed += (sender, e) =>
{
// broadcast to listeners whether they are listening or not
IHubConnectionContext _clients = GlobalHost.ConnectionManager.GetHubContext<ChatHub>().Clients;
_clients.Group("group1FixedName").showMessage("Some message for group 1 only");
_clients.Group("group2FixedName").showMessage("Some message for group 2 only");
// etc
};
aTimer.Start();
我最近从 beta1 升级到了 1.1.0 版。我开始观察到“删除”方法不起作用,因为即使我发起了“离开”,"client" (web browser) 仍在接收来自“其他”组的消息。请注意,“离开”组并不意味着关闭 Web 浏览器。它仍然在同一页面中(单页应用程序),离开/加入组是由选择触发的(例如组合框)。
集线器中的代码:
public Task Leave(string groupName)
{
return Groups.Remove(Context.ConnectionId, groupName)
.ContinueWith(z => Clients.Caller.showCallerMessage("You are now leaving " + groupName));
}
javascript客户端中的代码“离开组”:
chat.server.leave("group1FixedName");
javascript 客户端中“加入群组”的代码:
chat.server.join("group1FixedName");
Hub 中的加入代码:
public Task Join(string groupName)
{
return Groups.Add(Context.ConnectionId, groupName)
.ContinueWith(z => Clients.Caller.showCallerMessage("You are now listening to " + groupName));
}
我这里的实现有问题吗?
【问题讨论】:
-
您展示的 sn-ps 看起来不错。能不能做个示例应用放到github上?
-
谢谢@dfowler,我将制作我的应用程序的缩小版本,并确保我首先复制该问题。
-
我在这里上传了示例应用程序:github.com/ericpanorel/SignalrDebugForDfowler 在调试时,我发现自托管应用程序上的 beta 位仍然有效(没问题),即使我有客户端的最新位.当我也升级自托管应用程序的位时,描述的问题已经出现。
标签: signalr signalr-hub signalr.client owin