jamiewest / signalr_core

ASP.NET Core SignalR Dart Client
https://pub.dev/packages/signalr_core
MIT License
91 stars 58 forks source link

Hub handshake failed with error 'NoSuchMethodError: The method 'send' was called on null. #33

Closed Chris1234567899 closed 3 years ago

Chris1234567899 commented 3 years ago

I'm afraid I still receive this error. See https://github.com/jamiewest/signalr_core/issues/16

I have:

final connection = HubConnectionBuilder()
          .withUrl(
              url,
              HttpConnectionOptions(
                transport: HttpTransportType.webSockets,
                accessTokenFactory: _authService.getToken,
                logMessageContent: true,
                logging: (level, message) => print(message),
              ))
          .build();

      await connection.start();
      ...

I can call negotiate successfully but during handshake it breaks:

I/flutter ( 8194): Starting HubConnection.
I/flutter ( 8194): Starting connection with transfer format 'TransferFormat.text'.
I/flutter ( 8194): Sending negotiation request: https://10.0.2.2:44302/api/signalr/negotiate.
I/flutter ( 8194): The HttpConnection connected successfully.
I/flutter ( 8194): Sending handshake request.
I/flutter ( 8194): Hub handshake failed with error 'NoSuchMethodError: The method 'send' was called on null.
I/flutter ( 8194): Receiver: null
I/flutter ( 8194): Tried calling: send("{\"protocol\":\"json\",\"version\":1}\u001e")' during start(). Stopping HubConnection.
I/flutter ( 8194): type 'NoSuchMethodError' is not a subtype of type 'Exception'
I/flutter ( 8194): HubConnection failed to start successfully because of error '{type 'NoSuchMethodError' is not a subtype of type 'Exception'.toString}'.

Using it with signalR on azure. I can change the transporttype, but it does result in the same error.

Chris1234567899 commented 3 years ago

Ok I realized, it must have been because of returning a different key for the url from the negotiation than expected.

The package expects "url", I had "hubUrl" (from a different tutorial). Now it appears to work.

nadeendames96 commented 3 years ago

please tell me soluation

nadeendames96 commented 3 years ago

@Chris1234567899

Chris1234567899 commented 3 years ago

@nadeendames96 Signalr clients are supposed to send first a post request against a backend in order to authenticate. Your backend has to send back an url and an accessToken that the client uses co connect to the Signalr server.

I found this tutorial quite helpful for understanding the logic: https://anthonychu.ca/post/java-spring-boot-azure-signalr-service/

In my case my response from my backend was malformed (I had hubUrl instead of url).