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. #16

Closed nikitaabnave closed 4 years ago

nikitaabnave commented 4 years ago

I am trying to connect to server. But I am getting - Hub handshake failed with error 'NoSuchMethodError: The method 'send' was called on null.

Below is the Console log -

I/flutter (22642): log The HttpConnection connected successfully. I/flutter (22642): log Sending handshake request. I/flutter (22642): log Hub handshake failed with error 'NoSuchMethodError: The method 'send' was called on null. I/flutter (22642): Receiver: null I/flutter (22642): Tried calling: send("{\"protocol\":\"json\",\"version\":1}\u001e")' during start(). Stopping HubConnection. I/flutter (22642): log HubConnection failed to start successfully because of error '{type 'NoSuchMethodError' is not a subtype of type 'Exception'.toString}'. E/flutter (22642): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'NoSuchMethodError' is not a subtype of type 'Exception' E/flutter (22642): #0 HubConnection._startInternal (package:signalr_core/src/hub_connection.dart:215:41) E/flutter (22642): E/flutter (22642): #1 HubConnection._startWithStateTransitions (package:signalr_core/src/hub_connection.dart:151:13) E/flutter (22642): #2 HubConnection.start (package:signalr_core/src/hub_connection.dart:137:20)

Here is my code snippet -

final connection = HubConnectionBuilder().withUrl(_serverUrl, HttpConnectionOptions( transport:[HttpTransportType.webSockets,HttpTransportType.longPolling], logging: (level, message) => print('log $message'), )).withAutomaticReconnect().build();

  await connection.start();

Please help me to figure out this issue.

Mol0ko commented 4 years ago

I think you should pass one of HttpTransportType values to transport parameter, not a list:

final connection = HubConnectionBuilder().withUrl(
    _serverUrl,
    HttpConnectionOptions(
        transport: HttpTransportType.webSockets,
        logging: (level, message) => print('log $message'),
    )
).withAutomaticReconnect().build();

Did you try this?

https://github.com/jamiewest/signalr_core/blob/9cfeea4a86a78ce32f29a3147cf58532415ea814/lib/src/http_connection_options.dart#L19-L20

jamiewest commented 4 years ago

I don't love this option being dynamic, It was done to keep consistent with the ASP SignalR typescript client. I think it could be used for custom transports... I don't believe this parameter is supposed to receive a list though.

AliEasy commented 4 years ago

Any solution yet?

jamiewest commented 4 years ago

Only a single transport can be specified, it can be an HttpTransportType (enumeration) or by an implementation of type Transport. Your code is providing a list of HttpTransportType which is not valid. If your still having issues after this correction please open another issue. Thanks