【问题标题】:Setting the ping interval on the SignalR .NET Client在 SignalR .NET 客户端上设置 ping 间隔
【发布时间】:2022-12-14 18:39:18
【问题描述】:

我已经使用以下配置设置了一个 signalr API 端点(仅限 WS):

                .AddHubOptions<MyHub>(options =>
                {
                    options.ClientTimeoutInterval = TimeSpan.FromSeconds(120);
                    options.KeepAliveInterval = TimeSpan.FromSeconds(60);
                })

现在,.net 客户端应用程序每约 15 秒对端点执行一次 ping 操作,并在几次尝试后关闭。 如何配置 .net 客户端每 60 秒 ping 服务器一次? 我检查了以下代码,但没有帮助:

                .WithUrl("signalrendpointaddress", options =>
                {
                    options.CloseTimeout = TimeSpan.FromSeconds(120);
                    options.WebSocketConfiguration = (configuration) => { configuration.KeepAliveInterval = TimeSpan.FromSeconds(60); };
                })

【问题讨论】:

  • 可以尝试参考官方docKeepAliveIntervalServerTimeout都需要改。建议ServerTimeout值是KeepAliveInterval值的两倍。

标签: c# asp.net-core signalr signalr-hub


【解决方案1】:

如果要将KeepAliveInterval更改为60秒,则需要更改serverTimeoutInMilliseconds

var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();
connection.serverTimeoutInMilliseconds = 2 * 60 * 1000;

服务器超时毫秒数:

服务器超时(以毫秒为单位)。如果此超时过去后仍未收到来自服务器的任何消息,则连接将因错误而终止。默认超时值为 30,000 毫秒(30 秒)。

更多详情可以参考官方doc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2018-02-28
    • 1970-01-01
    相关资源
    最近更新 更多