小编Kar*_*n63的帖子

一段时间后信号 R 连接状态为 0

我正在使用@aspnet/signalr连接到集线器,并从集线器调用该方法以返回一些数据。

当我第一次初始化服务器时,连接正常建立,但是如果我刷新窗口 3 或 4 次,客户端将停止向服务器发送连接请求。

我尝试记录HubConnectionconnectionState起初等于1但在问题产生后connectionState总是等于0

这是我构建 hubConnection 的方式:

buildConnection() {
this.hubConnection = new HubConnectionBuilder()
.withUrl(this.tradesService.getStockQuotationsHubUrl())
.build();
this.hubConnection.serverTimeoutInMilliseconds = 1000 * 10;
this.hubConnection.onclose(() => setTimeout(() => this.startSignalRConnection(), 2000));}
Run Code Online (Sandbox Code Playgroud)

这是我启动 hubConnection 的方式:

startConnection() {
    this.hubConnection
      .start()
      .then(() => {
      this.hubConnection.on('updateMethod', (data: any) => {
        
          this.store.push([
            { type: 'update', key: data.stockID, data },
          ]);
         
        });
      this.dataSource = new DataSource({
          store: this.store,
          reshapeOnPush: true,
        });
      });}
Run Code Online (Sandbox Code Playgroud)

注意:我在我的页面中同时列出了 5 个集线器,但唯一有问题的是这个。

[更新]

问题出在服务器上,因为当我重新启动服务器时,客户端和服务器之间会重新建立连接,但是如果客户端多次刷新或退出页面,集线器甚至不会尝试连接到客户端 …

c# signalr devextreme asp.net-core angular

5
推荐指数
1
解决办法
493
查看次数

标签 统计

angular ×1

asp.net-core ×1

c# ×1

devextreme ×1

signalr ×1