gpt4 book ai didi

c# - SignalR - 更改服务器超时响应

转载 作者:行者123 更新时间:2023-12-03 13:31:41 26 4
gpt4 key购买 nike

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

public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddSignalR().AddHubOptions<ActivityHub>(options => {
options.ClientTimeoutInterval = TimeSpan.FromMinutes(30);
options.KeepAliveInterval = TimeSpan.FromMinutes(15);
});
}

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

最佳答案

when i set the KeepAliveInternal and ClientTimeOutInterval a value in the hub configuration, the application ignore it and always set to "30,000ms" for both.

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

enter image description here

要修复此问题,您可以尝试设置 HubConnection 的 serverTimeoutInMilliseconds,如下所示。

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

connection.serverTimeoutInMilliseconds = 120000;

测试结果

enter image description here

注意:

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

hubOptions.ClientTimeoutInterval = TimeSpan.FromMinutes(2);
hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(1);

关于c# - SignalR - 更改服务器超时响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59586226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com