Does Signalr change connectionId OnReconnected method?
Asked Answered
C

2

6

I was wondering if signalr changes the connectionId on OnReconnected method? as I'm mapping a list of users to their connection ids so if the reconneced event raised on the server due to slow connection for example will the connectionId will be changed ?

Cavie answered 1/8, 2017 at 0:18 Comment(0)
D
8

No. The connectionId does not change in an OnReconnected event.

  • The OnReconnected fires automatically(if you're using a signalR client) within the disconnect timeout in case there is a network issue and a keep alive is missed.
  • If the network is disrupted or the server is unable to process the OnReconnected event for longer than the disconnect timeout, the connection will be disconnected on the server and a new connection will need to be made. This making a new connection is not automatic. The client code will have to call a connection.Start() to create a new connection.
  • If the client comes back with the old connectionId, it will not go through as that connection would be in a disconnected state.

So if you are mapping connectionIDs with Users then you need to make sure that the connection Id is updated with the new connectionId in every OnConnected event and deleted in every OnDisconnected event on the server .

Demark answered 2/8, 2017 at 13:45 Comment(3)
odd. In my experience it consistently does change. I'm using the Azure SignalR service. Maybe that makes a difference.Enumerate
From the docs: "Since the connection looks entirely new to the server, a new connectionId is provided to the onreconnected callback." - learn.microsoft.com/en-us/aspnet/core/signalr/…Satem
thats really weird, my connectionId changes on every reconnect too in WCFPlatelet
D
3

I don't believe the OnReconnect will change the connectionID. However, that depends on what the cause of the problem is.

If the client dropped it's internet connection for example and then picked back up, OnReconnect fires and the user should have the same connectionID.

If the server rebooted or IIS restarted, then you have a different situation and when your clients refresh it will appear as a OnConnect and get a new connectionID.

Disability answered 1/8, 2017 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.