什么时候在signalR中发生重新连接? [英] When does a reconnect in signalR occur?

查看:584
本文介绍了什么时候在signalR中发生重新连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用SignalR,并试图确定何时发生集线器重新连接。我在网上找不到令人满意的解释。有人可以解释何时/为什么重新连接?

I've started working with SignalR and was trying to figure out when a Hub Reconnect occurs. I didn't find any satisfying explanation on the web. Can someone explain when/why a reconnect occurs?

推荐答案

当客户端脱机然后不久后重新获得连接时,就会发生集线器重新连接。 SignalR配置值在很大程度上决定了以下示例的时间戳,因此无需逐字记录时间。

A hub reconnect occurs when a client goes offline then regains connectivity shortly after. SignalR configuration values largely determine the time stamps of the following examples so do not take the times verbatim.

这里有几个示例,其结果(时间格式为m:ss)涉及重新连接行为:

Here are several examples and their outcomes (time format m:ss) involving reconnecting behavior:

当我提到以下内容时,我指的是服务器端的Hub方法


  • OnConnected

  • OnDisconnected

  • OnReconnected

1)

0:00-客户端连接到服务器,触发了OnConnected

0:10-客户端丢失由于ISP问题导致连接失败(并意识到它失去了连接)

0:15-客户端重新获得连接

0:16-触发了OnReconnected事件

1)
0:00 - Client connects to server, OnConnected is triggered
0:10 - Client loses connection due to ISP issues (and realizes it loses connection)
0:15 - Client Regains connectivity
0:16 - OnReconnected event is triggered

2)

0:00-客户端连接到服务器,触发了OnConnected

0:10-客户端由于以下原因失去了连接拉以太网电缆(未意识到它已断开连接)

0:15-客户端重新获得connectiv ity

这里可能发生两件事

A:0:16-什么也没发生,客户端继续其先前的连接

B:0:〜45-客户端意识到其断开连接*

B:0:46-客户端转换为重新连接状态

B:0:47-客户端成功重新连接并且OnReconnected事件被触发。

2)
0:00 - Client connects to server, OnConnected is triggered
0:10 - Client loses connection due to pulling ethernet cable (doesn't realize it's disconnected)
0:15 - Client Regains connectivity
Two things can happen here
A: 0:16 - Nothing happens and client continues on with its previous connection
B: 0:~45 - Client Realizes its disconnected *
B: 0:46 - Client transitions into the reconnecting state
B: 0:47 - Client successfully reconnects and the OnReconnected event is triggered.

3)

0:00-客户端连接到服务器,触发了OnConnected

0:10-客户端由于拉拔以太网电缆而失去连接(未意识到它已断开连接)

0:〜45-客户端意识到其断开连接*

0: 46-客户端转换为重新连接状态

1:15-服务器确定客户端已经离开太久,然后忘记了这一点,排队一个断开连接命令供客户端重新连接时接收稍晚一点。 ***

1:15-触发了OnDisconnected

1:16-客户端重新获得连接

1:17-客户端进行了软重新连接(不会触发OnReconnected)

1:18-客户端检索断开连接命令

1:19-客户端调用停止并进行软断开连接(不会触发OnDisconnected)

3)
0:00 - Client connects to server, OnConnected is triggered
0:10 - Client loses connection due to pulling ethernet cable (doesn't realize it's disconnected)
0:~45 - Client Realizes its disconnected *
0:46 - Client transitions into the reconnecting state
1:15 - Server determines that client has been gone for too long and then forgets about it, queuing up a "disconnect" command for the client to receive if it reconnects slightly later. ***
1:15 - OnDisconnected is triggered
1:16 - Client regains connectivity
1:17 - Client does a "soft" reconnect (does not trigger OnReconnected)
1:18 - Client retrieves the "disconnect" command
1:19 - Client calls "stop" and does a soft disconnect (does not trigger OnDisconnected)

4)

0:00-客户端连接到服务器,触发了OnConnected

0:10-客户端由于拉拔以太网电缆而失去连接(未意识到它已断开连接)

0:〜45-客户端实现了其断开连接*

0:46-客户端转换进入重新连接状态

1:15-服务器确定客户端已离开太久,然后忘记了这一点,排队一个断开连接命令,以便客户端稍晚重新连接时可以接收。 ***

1:15-触发了OnDisconnected

1:30-客户端停止尝试重新连接(尝试时间过长)**

1: 30-客户端转换为断开状态

4)
0:00 - Client connects to server, OnConnected is triggered
0:10 - Client loses connection due to pulling ethernet cable (doesn't realize it's disconnected)
0:~45 - Client Realizes its disconnected *
0:46 - Client transitions into the reconnecting state
1:15 - Server determines that client has been gone for too long and then forgets about it, queuing up a "disconnect" command for the client to receive if it reconnects slightly later. ***
1:15 - OnDisconnected is triggered
1:30 - Client stops trying to reconnect (been trying too long) **
1:30 - Client transitions into disconnected state

*由于客户端保持活动状态,请检查:用于确定客户端何时由于缺少活动状态而脱机。

* Due to client side keep alive check: Used to determine when a client is offline due to lack of keep alives. Not utilized for the long polling transport

**由于客户端断开超时:用于确定客户端何时重新连接太长时间服务器在这段时间内遗忘了客户端的时间段

** Due to client side disconnect timeout: Used to determine when a client has been reconnecting for too long of a period and chances are the server has forgotten about the client during the time

***由于服务器断开连接超时:用于确定什么时候应该忘记一个客户。一旦在服务器上将连接标记为无效后,该时间跨度就会开始累积。最终,服务器会为客户端的主题排队一个断开连接命令,该命令告诉客户端(如果重新连接)它需要开始新的连接。清理完主题后,该命令将从服务器中消失。

*** Due to server disconnect timeout: Used to determine when a client should be forgotten about. It's a time span that starts accruing once a connection is tagged as dead on the server. Ultimately the server queues a disconnect command for the client's topic which tells the client (if it reconnects) that it needs to start a fresh connection. The command will disappear from the server when the topic is cleaned up.

希望这会有所帮助!

这篇关于什么时候在signalR中发生重新连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆