SignalR Client HubConnection.Start() 抛出异常并且不会像文档中所说的那样继续尝试连接
SignalR Client HubConnection.Start() throws exception and doesn't keep trying to connect like the documentation says it should
当我调用 HubConnection.Start() 到一个尚未启动且尚未 运行 的端点时,我希望 HubConnection 会做任何它应该做的事情以不断使连接。至少我认为 SignalR 客户端指南是这样告诉我的:
When you call the Start method in a SignalR client, you are providing SignalR client code with all the information it needs in order to establish a physical connection to a server. SignalR client code uses this information to make an HTTP request and establish a physical connection that uses one of the four transport methods. If the transport connection fails or the server fails, the SignalR connection doesn't go away immediately because the client still has the information it needs to automatically re-establish a new transport connection to the same SignalR URL. In this scenario, no intervention from the user application is involved, and when the SignalR client code establishes a new transport connection, it does not start a new SignalR connection. The continuity of the SignalR connection is reflected in the fact that the connection ID, which is created when you call the Start method, does not change.
但是,我没有看到这个。 Start() 抛出异常。即使我忽略它,然后启动我的服务器集线器,HubConnection 也不会尝试再次连接。
我是不是对指南有误解?在所有 SignalR 客户端重新连接逻辑发生之前,我是否必须首先成功连接?
您必须先建立初始连接。
根据 David Fowl 的说法
...if the connection failed to start in the first place then it
won't auto reconnect.
他还说这已经完成了...
Because it's a more natual API. If you connect to a service that is
down chances are something is really wrong. If you were connected at
some point and the connection dropped , signalr will retry for a
little bit then give up and disconnect. They are very different
scenarios and we try to keep the connection up if there's blips in the
network but not when failing to start the connection altogether. That
behavior is more predictable.
此外,here is a really awesome SO post 详细介绍了一系列不同的断开连接场景
我认为您可能混淆了两件不同的事情 - 使用传输回退启动连接并重新连接。如果您没有明确说明要使用哪种传输方式,SignalR 客户端将尝试使用所有可用的传输方式(websockets、服务器发送的事件、长轮询和永久帧(JS 客户端))进行连接。如果开始与给定传输的连接失败,客户端将尝试使用列表中的下一个传输,使用与前一个传输相同的数据(url、cookies 等)。从这个意义上讲,不需要用户干预来尝试不同的传输方式。但是,如果开始与最后一个传输的连接失败,客户端将放弃并抛出异常。换句话说 - 客户端不会重新尝试与已经失败的传输建立连接。
连接成功后,如果连接丢失,客户端将尝试重新连接。在这种情况下,它将使用它最初连接到服务器的相同传输,并且不会尝试使用其他传输。如果客户端在一定时间内无法使用此传输重新连接到服务器,连接将被关闭。
当我调用 HubConnection.Start() 到一个尚未启动且尚未 运行 的端点时,我希望 HubConnection 会做任何它应该做的事情以不断使连接。至少我认为 SignalR 客户端指南是这样告诉我的:
When you call the Start method in a SignalR client, you are providing SignalR client code with all the information it needs in order to establish a physical connection to a server. SignalR client code uses this information to make an HTTP request and establish a physical connection that uses one of the four transport methods. If the transport connection fails or the server fails, the SignalR connection doesn't go away immediately because the client still has the information it needs to automatically re-establish a new transport connection to the same SignalR URL. In this scenario, no intervention from the user application is involved, and when the SignalR client code establishes a new transport connection, it does not start a new SignalR connection. The continuity of the SignalR connection is reflected in the fact that the connection ID, which is created when you call the Start method, does not change.
但是,我没有看到这个。 Start() 抛出异常。即使我忽略它,然后启动我的服务器集线器,HubConnection 也不会尝试再次连接。
我是不是对指南有误解?在所有 SignalR 客户端重新连接逻辑发生之前,我是否必须首先成功连接?
您必须先建立初始连接。
根据 David Fowl 的说法
...if the connection failed to start in the first place then it won't auto reconnect.
他还说这已经完成了...
Because it's a more natual API. If you connect to a service that is down chances are something is really wrong. If you were connected at some point and the connection dropped , signalr will retry for a little bit then give up and disconnect. They are very different scenarios and we try to keep the connection up if there's blips in the network but not when failing to start the connection altogether. That behavior is more predictable.
此外,here is a really awesome SO post 详细介绍了一系列不同的断开连接场景
我认为您可能混淆了两件不同的事情 - 使用传输回退启动连接并重新连接。如果您没有明确说明要使用哪种传输方式,SignalR 客户端将尝试使用所有可用的传输方式(websockets、服务器发送的事件、长轮询和永久帧(JS 客户端))进行连接。如果开始与给定传输的连接失败,客户端将尝试使用列表中的下一个传输,使用与前一个传输相同的数据(url、cookies 等)。从这个意义上讲,不需要用户干预来尝试不同的传输方式。但是,如果开始与最后一个传输的连接失败,客户端将放弃并抛出异常。换句话说 - 客户端不会重新尝试与已经失败的传输建立连接。
连接成功后,如果连接丢失,客户端将尝试重新连接。在这种情况下,它将使用它最初连接到服务器的相同传输,并且不会尝试使用其他传输。如果客户端在一定时间内无法使用此传输重新连接到服务器,连接将被关闭。