SignalR-更改服务器超时响应

问题描述 投票:2回答:2

我已经创建了SignalR应用程序,但是当我在集线器配置中将KeepAliveInternal和ClientTimeOutInterval设置为一个值时,应用程序将忽略它,并且两者都始终设置为“ 30,000ms”。这是我的代码:

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddRazorPages();
     services.AddSignalR().AddHubOptions<ActivityHub>(SetConfig);

     // Local function to set hub configuration
     void SetConfig(HubOptions<ActivityHub> options)
     {
         options.ClientTimeoutInterval = TimeSpan.FromMinutes(30);
         options.KeepAliveInterval = TimeSpan.FromMinutes(15);
     }
}

我已经阅读了SignalR Net Core文档,并且这两个属性没有限制。即使我将超时值设置为不同的值,超时也始终为“ 30,000”。

c# azure asp.net-core signalr
2个回答
0
投票

请参考configuring server options的官方文档

您可以尝试按以下方式进行配置:

public void ConfigureServices(IServiceCollection services)
{
    services.AddSignalR(hubOptions =>
    {
        hubOptions.ClientTimeoutInterval = TimeSpan.FromMinutes(30);
        hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(15);
    });
}

或对于单个集线器:

services.AddSignalR().AddHubOptions<MyHub>(options =>
{
    options.ClientTimeoutInterval = TimeSpan.FromMinutes(30);
    options.KeepAliveInterval = TimeSpan.FromMinutes(15);
});

0
投票

当我在集线器配置中将KeepAliveInternal和ClientTimeOutInterval设置为一个值时,应用程序将忽略它,并且始终将两者都设置为“ 30,000ms”。

对于SignalR JavaScript客户端,默认serverTimeoutInMilliseconds值为30,000毫秒(30秒)。如果将HubOptions的serverTimeoutInMilliseconds设置为大于30秒的值,但未在客户端为HubConnection的KeepAliveInterval指定合适的值,则连接将因错误而终止,如下所示。

serverTimeoutInMilliseconds

要解决此问题,您可以尝试设置HubConnection的enter image description here,如下所示。

serverTimeoutInMilliseconds

测试结果

var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub") .configureLogging(signalR.LogLevel.Trace) .build(); connection.serverTimeoutInMilliseconds = 120000;

注意:

在上面的测试中,我用下面的代码片段配置了SignalR集线器,我们发现ping消息每60秒自动发送一次。

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.