asp.net – SignalR 2.0超时连接
发布时间:2020-05-25 16:13:21 所属栏目:asp.Net 来源:互联网
导读:我正在使用SignalR.But有一个关于超时的问题. 几分钟后超时消失,无法正常工作. 如何在SignalR 2.0中设置超时连接? 您可以在Owin Startup类中使用以下配置. // Make long polling connections wait a maximum of 110 seconds for a // response. When that ti
|
我正在使用SignalR.But有一个关于超时的问题. 几分钟后超时消失,无法正常工作. 如何在SignalR 2.0中设置超时连接? 解决方法您可以在Owin Startup类中使用以下配置.// 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(40);
// 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);
//Setting up the message buffer size
GlobalHost.Configuration.DefaultMessageBufferSize = 500;
此外,当您希望始终将客户端连接到服务器时,可以尝试在disconnect hub事件中连接它. var tryingToReconnect = false;
$.connection.hub.disconnected(function () {
//TODO: write the logic to reconnect to server.
if(!tryingToReconnect) {
// notifyclient about disconnection
setTimeout(function() {
$.connection.hub.start();
},5000); // Restart connection after 5 seconds.
}
});
$.connection.hub.reconnecting(function() {
tryingToReconnect = true;
console.log("reconnecting...");
});
$.connection.hub.reconnected(function() {
tryingToReconnect = false;
console.log("Reconnected");
}); (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-3 – 在Razor / MVC3中显示db的图像
- asp.net-mvc-3 – 发布到列表MVC3
- asp.net – Web.Config中的Assemblies节点的目的是什么?
- asp.net-mvc – ASP包中的绝对URL
- asp.net-mvc – mvc razor @helper可以返回非编码标签吗?
- ASP.NET MVC验证使用qTip jQuery插件
- 如何从asp.net中的javascript调用codebehind函数?
- asp.net-mvc – 在ASP.NET MVC中定制授权
- asp.net-mvc – 从基本控制器继承LINQ-to-SQL数据上下文
- ASP.Net使用DBNULL检查值
推荐文章
站长推荐
- ASP.Net核心 – 获取帖子表格的所有数据
- asp.net-mvc-3 – 扩展MVC3剃刀Html.LabelFor添加
- asp.net – 什么放在会话变量中
- asp.net-mvc – Visual Studio断点未被击中
- mvc-mini-profiler – MVC MiniProfiler与ASP.NE
- asp.net中的SqlDependency
- asp.net-mvc – 如何将名为“file []”的已发布数
- asp.net – jqgrid editurl:控制器动作参数
- asp.net – 是存储库单例或静态还是没有这些?
- asp.net – 问题映射HttpHandler – HTTP错误404
热点阅读
