我正在Asp.Net Core 3.1和Angular8上使用Azure SignalR。我还在客户端使用了withAutomaticReconnect()选项。它与天蓝色信号器成功连接。但是一段时间后,它显示此错误消息并再次连接到WebSocket。
错误:连接已断开,错误为'错误:服务器超时,但未收到来自服务器的消息。'
默认serverTimeoutInMilliseconds
值为30,000毫秒(30秒),如果在没有收到来自服务器的任何消息的情况下超时,则连接将终止,并出现上述错误。
请检查您是否配置/更改了SignalR集线器服务器的serverTimeoutInMilliseconds
。
[更改KeepAliveInterval
option时,我们应该在客户端更改KeepAliveInterval
设置。推荐的KeepAliveInterval
值是serverTimeoutInMilliseconds
值的两倍。
例如:
在中心服务器上,将KeepAliveInterval更改为1分钟
serverTimeoutInMilliseconds
在客户端,将serverTimeoutInMilliseconds更改为2分钟
KeepAliveInterval
测试结果
services.AddSignalR(hubOptions =>
{
hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(1);
}).AddAzureSignalR();