【发布时间】:2018-12-09 23:38:01
【问题描述】:
在我的带有 ASP.NET 服务器应用程序的 angular6 网站中, 我希望 singnalR 客户端应始终与集线器(服务器)保持连接。为此,使用以下代码快照在断开连接的事件上开始连接。
this.connection.start().done((data: any) => {
console.log('Now connected');
this.connectionId = this.connection.id;
this.connectionEstablished.emit(true);
this.connectionExists = true;
}).fail((error: any) => {
this.connectionEstablished.emit(false);
});
this.connection.reconnecting(() => {
this.tryingToReconnect = true;
});
this.connection.reconnected(() => {
this.tryingToReconnect = false;
});
this.connection.error((error: any) => {
this.initialize();
});
this.connection.disconnected(() => {
if (this.tryingToReconnect) {
setTimeout(() => {
this.initialize();
}, 5000);
}
});;
由于上面的代码,signalr 会产生问题,例如 在以下情况下会导致客户端浏览器崩溃和内存泄漏,例如,
如果客户端互联网连接出现问题几个小时,那段时间 singalr 会不断尝试创建与集线器的连接。由于网络问题,在浏览器控制台中无限记录连接错误,直到与 hub 连接成功
-
如果我关闭服务器,那时间也会 singalR 在浏览器控制台中无限记录连接错误,直到与 hub 成功连接
如何解决signalr始终与Hub保持连接的问题?
【问题讨论】:
标签: asp.net-mvc signalr