我在 aspx 页面上使用 signalr 0.4,
var hub = $.connection.FooHub;
hub.disconnected(function () {
log("Server has disconnected");
});
hub.ShowInfo = function (Info) { .... }
$("#Button1").click(function () {
hub.FooFunction('foo');
});
$.connection.hub.start();
集线器定义为:
public class FooHub : Hub, IDisconnect
{
~FooHub()
{
log.Debug("FooHub Destroy");
}
public FooHub()
{
log.Debug("FooHub Startup");
}
public bool FooFunction(string stuff)
{
log.Debug("Hub FooFunction");
Clients.ShowInfo(someInfo);
return true;
}
public Task Disconnect()
{
// Query the database to find the user by it's client id etc. etc.
MyController.Disconnect(Context.ConnectionId);
log.Debug("Hub Disconnnect " + Context.ConnectionId);
return null;
}
......
}
当我打开页面并立即单击 Button1
时,它调用集线器,集线器又调用页面上的 ShowInfo 功能。
使用 Firebug,我可以看到信号器正在使用长轮询进行通信。所以一切都按预期工作。
但是当我等待几分钟时,
我看到了
- FooHub 被销毁
- 在集线器中调用断开连接,
但是在页面上没有新的连接
Firebug 显示旧的连接仍在执行
,当我点击按钮时 -
- FooFunction 被调用(我在萤火虫中看到了一个新的连接)
- FooHub 已创建
- FooFunction 在 Hub 中执行(Log 中有一行)
- 但未执行 ShowInfo
这是 SignalR 中的错误还是我必须做其他事情才能获得 ShowInfo 调用?
更新(可能的答案):
它使用的是 Forever-Frame 而不是长轮询。
此外,这个问题似乎主要发生在使用移动互联网(usb-stick)和 Firefox 时。
将传输更改为长轮询似乎可以解决此问题。