连接丢失时,文档中缺少重新连接功能

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

我在我的角度5应用程序https://github.com/HNeukermans/ng2-signalr中使用此库作为signalr

信号器在一段时间后断开连接。我没有看到任何文档如何从客户端重新连接。如果有人知道怎么做,请帮忙

angular signalr
2个回答
1
投票

我建议您在错误时应用settimeout重新启动或再次启动连接。

this.connection.errors.subscribe((error: any) => {
     this.errors.push(error);
console.log('Error while establishing connection... Retrying...');
    setTimeout(() => this.connection.start(), 3000);
});

或者你可以aspnet /信号HubConnection


1
投票

您可以实现自定义重试,但不确定它是否有效。通过以下方式监听连接状态:

this.connection.status.subscribe((status: ConnectionStatus) => {
     this.statuses.push(status);
});

在错误,一些延迟呼叫连接再次启动后。

或者您可以使用Microsoft的官方库进行SignalR:aspnet/signalr而不是ng2-signalr。使用Angular非常简单。查看这些文章:

© www.soinside.com 2019 - 2024. All rights reserved.