SignalR Hub OnDisconnected 何时在服务器端引发,对于崩溃或关闭而不调用Stop method?
我正在使用 SignalR .NET 客户端进行测试,而不是 javascript 客户端。
如果我打电话给Stop客户端上的方法,集线器将引发断开连接时立即方法。
但是如果我关闭客户端或终止进程,集线器将引发断开连接时方法仅在大约 10 秒后完成。
如何即时检测到客户端断线?
阅读了文档后SignalR 事件在这里 http://www.asp.net/signalr/overview/hubs-api/handling-connection-lifetime-events,我发现了这个部分:
当连接处于非活动状态时,服务器会定期发送
keepalive 数据包发送给客户端。截至本文发表之日
写入,默认频率是每10秒一次
有一节描述了如何更改保活设置,例如
protected void Application_Start(object sender, EventArgs e)
{
// Make long polling connections wait a maximum of 110 seconds for a
// response. When that time expires, trigger a timeout command and
// make the client reconnect.
GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);
// Wait a maximum of 30 seconds after a transport connection is lost
// before raising the Disconnected event to terminate the SignalR connection.
GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30);
// For transports other than long polling, send a keepalive packet every
// 10 seconds.
// This value must be no more than 1/3 of the DisconnectTimeout value.
GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10);
RouteTable.Routes.MapHubs();
}
因此,您可以考虑降低该值,以便在客户端连接断开时更快地收到通知。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)