【问题标题】:Azure SignalR withAutomaticReconnect() "Error: Connection disconnected with error"... on Angular8 & Asp.Net Core 3.1Azure SignalR withAutomaticReconnect()“错误:连接因错误而断开”...在 Angular8 和 Asp.Net Core 3.1 上
【发布时间】:2020-05-20 18:22:52
【问题描述】:

我在 Asp.Net Core 3.1 和 Angular8 上使用 Azure SignalR。我还在客户端使用了 withAutomaticReconnect() 选项。它与 azure signalr 成功连接。但是一段时间后它会显示此错误消息并再次连接到 WebSocket。

【问题讨论】:

  • 能否展示您的相关代码并告诉我们您的 Azure SignalR 服务的服务模式?
  • 私有 createConnection() { let accessToken = this.authService.getAuthToken(); this.hubConnection = new HubConnectionBuilder() .withUrl(${environment.client.signalr_endpoint}, { accessTokenFactory: () => accessToken }) .withAutomaticReconnect() .build(); this.startConnection(); this.registerEvents(); } private startConnection() { this.hubConnection.start().then(() => { console.log('SignalR Connected.'); }).catch(err => { }); } Azure SignalR 服务模式:经典

标签: azure asp.net-core-signalr azure-signalr


【解决方案1】:

错误:连接因错误“错误:服务器超时而未收到来自服务器的消息”而断开。

serverTimeoutInMilliseconds 的默认值为 30,000 毫秒(30 秒),如果超过此超时时间而没有收到来自服务器的任何消息,则连接将终止并出现上述错误。

请检查您是否配置/更改了 SignalR 集线器服务器的 KeepAliveIntervaloption。

在更改KeepAliveInterval 时,我们应该在客户端更改serverTimeoutInMilliseconds 设置。并且推荐的serverTimeoutInMilliseconds 值是KeepAliveInterval 值的两倍。

例如:

在中心服务器上,将 KeepAliveInterval 更改为 1 分钟

services.AddSignalR(hubOptions =>
{
    hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(1);
}).AddAzureSignalR();

在客户端,将 serverTimeoutInMilliseconds 更改为 2 分钟

this.hubConnection.serverTimeoutInMilliseconds = 120000;

测试结果

【讨论】:

    猜你喜欢
    • 2020-09-05
    • 1970-01-01
    • 2020-06-04
    • 1970-01-01
    • 2021-12-11
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    相关资源
    最近更新 更多