aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Disconnect / Reconnect

Open aswanevelder opened this issue 9 years ago • 22 comments

Hi guys,

Are there javascript events available yet for Disconnect and Reconnect as was available in SignalR 2?

Thanks

aswanevelder avatar Oct 26 '17 08:10 aswanevelder

@aswanevelder I don't think so, at least I couldn't find it. I'm doing it using onclose event and just creating a brand new HubConnection 🤔

austinfelipe avatar Oct 26 '17 14:10 austinfelipe

There is no reconnect in this version of SignalR so there is no event. onclose is called when the connection is closed. You can now use websockets to connect to SignalR (i.e. no client is needed) - here is an example (which I need to finish and merge but it should give you an idea)

moozzyk avatar Oct 26 '17 15:10 moozzyk

We're looking at adding the automatic reconnect functionality back to SignalR in the next preview release.

davidfowl avatar Oct 27 '17 07:10 davidfowl

Thanks guys, @davidfowl looking forward to it!

aswanevelder avatar Oct 27 '17 07:10 aswanevelder

@davidfowl sounds great! Do you have road map for the next few months?

KirilRusev avatar Nov 01 '17 10:11 KirilRusev

@davidfowl @aswanevelder @KirilRusev
Please don't add reconnect. Its kind of confusing to manage. If client get disconnected, client can initiate reconnect. Its better that server should not manage reconnects.

AwsomeCode avatar Nov 01 '17 11:11 AwsomeCode

It’s all client side. All we’re going to do is make sure the connection is reusable and there’s a way to auto reconnect. The server isn’t managing anything

davidfowl avatar Nov 01 '17 19:11 davidfowl

Restarting the connection is now supported in the .NET client (in PR #1147).

#1171 is tracking adding support to the TypeScript client.

Given that, I'm going to close this issue. Feel free to comment if you still have concerns!

analogrelay avatar Dec 13 '17 21:12 analogrelay

Reopening, we are going to be adding automatic reconnect

Closed event called once reconnect tries are done Need to decide on number of reconnect tries Add configurability Back-off delay between reconnect tries StopAsync stops reconnect Keep connection re-usability

BrennanConroy avatar Jan 26 '18 23:01 BrennanConroy

We are going to make the connection restartable (so it's easy to add restart logic), but not automatically restart. We can investigate adding automatic reconnection in a future release.

analogrelay avatar Mar 22 '18 20:03 analogrelay

Hi guys, I'm developing a local dashboard web app that fetch data from many Rpi connected to the same local network. I'm using HubConnection on client side, with a stream subscribe. It works very well except for the fact that sometimes when I navigate to another page and then return to the dashboard page, I got this error: "cannot send data if the connection is not in the 'connected' state". If I try to refresh the page I got the same error, but if I try to refresh the page using CTRL+F5 (clear cache) It works. I don't understand why, Any Ideas?

Here's my client code: snip

Thanks :)

Frank802 avatar Apr 06 '18 06:04 Frank802

After some tests, I discover that the problem was a 'timing problem'. I was checking the state of my application in order to start the streaming in the windows on load event where the signalR connection sometime was still in connecting state (code=1), that's why sometimes I got that error. I've found this sample that is very helpful to handle this kind of scenario!

Frank802 avatar Apr 06 '18 10:04 Frank802

Disussion is mainly about JavaScript client I guess. Are you also planning to implement Reconnect in .NET Client? Maybe I should start new issue for that?

kmorcinek avatar Apr 30 '18 11:04 kmorcinek

When we implement automatic reconnect (just to clarify, manual reconnecting is possible today by simply calling StartAsync after the Closed event fires), it will be in both clients.

analogrelay avatar Apr 30 '18 15:04 analogrelay

@aswanevelder @davidfowl @kmorcinek Guys can you take a look at my implementation of automatic reconnect for .NET Client and test it to see if it works for you. https://www.radenkozec.com/net-core-signalr-automatic-reconnects/

radenkozec avatar Aug 23 '18 07:08 radenkozec

@radenkozec The sample you posted looks good, but you shouldn't have to recreate the HubConnection each time. If you're seeing issues with reusing the same HubConnection instance, let us know in a new issue.

analogrelay avatar Aug 23 '18 15:08 analogrelay

@anurse Thanks for feedback. I have improved my code to re-use HubConnection.

radenkozec avatar Aug 23 '18 19:08 radenkozec

I was about to ask clarifications about how to handle reconnect on the typescript client but I found this in the meantime: https://github.com/aspnet/Docs/issues/6757

I must say your release process makes me a bit confused but maybe it's just me. Probably it doesn't help (me) that you have .NET and Typescript clients in the same repository. Talking about the Typescript client here, you seem to have some 2.x versions finalised but latest version on npm is 1.0.3, so I don't even know if I will be able to reconnect with 1.03.

ghost avatar Sep 06 '18 10:09 ghost

you seem to have some 2.x versions finalised

The SignalR versions should be consistent across NuGet and NPM. Both the .NET and JavaScript clients share the same version number and release simultaneously, hence they are in the same repo. The issue you're referring to is that SignalR is part of ASP.NET Core. The entire ASP.NET Core platform is at version 2.1 (with version 2.2 being developed now). However, the version of SignalR included in those builds are 1.0 (and 1.1 in the next release).

We recongize this is a bit confusing and are planning to resolve this in the next major version when we can align builds.

A handy reference table:

ASP.NET Core Version SignalR NuGet/NPM Package Version
2.1.x 1.0.x
2.2.x 1.1.x

analogrelay avatar Sep 06 '18 18:09 analogrelay

@anurse Thank you for the clarification.

ghost avatar Sep 07 '18 07:09 ghost