2012-04-12 275 views
4

我使用SignalR和Asp.net MVC创建了聊天应用程序。如果用户闲置一段时间,他没有收到来自服务器的任何消息。SignalR持久连接的超时时间是多少?

SignalR持久连接有没有超时?

如果是,我该如何修改或重新激活我的连接?

回答

6

对于任何连接,SignalR的默认超时值都是110秒。它会自动重新连接,你不应该错过任何消息。这听起来像你有其他问题。如果你想调整超时0.4这样的(假设asp.net):

// Make idle connections reconnect every 60 seconds 
AspNetHost.DependencyResolver.Resolve<IConfigurtionManager>().ReconnectTimeout = TimeSpan.FromSeconds(60); 

确保您添加使用SignalR.Infrastructure得到解决扩展方法(我们在接下来的这个固定版)。

+0

在哪里可以找到IConfigurationManager接口? – 2012-04-13 14:29:59

+0

SignalR.Configuration。只是要清楚,这不会帮助你消失的问题。我不是100%确定你想要解决什么问题。 – davidfowl 2012-04-13 15:57:30

+0

如果这不起作用,那么更短或更长的超时有什么优点和缺点?会保持积极的帮助吗? – regularmike 2012-05-23 16:19:16

9

这现在已经更新过的Wiki上https://github.com/SignalR/SignalR/wiki/Configuring-SignalR

代码

using System; 
using SignalR; 

namespace WebApplication1 
{ 
    public class Global : System.Web.HttpApplication 
    { 
     void Application_Start(object sender, EventArgs e) 
     { 
      // Make connections wait 50s maximum for any response. After 
      // 50s are up, trigger a timeout command and make the client reconnect. 
      GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(50); 
     } 
    } 
}