Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

.net - When does a reconnect in signalR occur?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

When I Mention the following i am referring to the server side Hub method

  • OnConnected
  • OnDisconnected
  • 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 - 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 - 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 - 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.

Hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...