jamiewest/signalr_core

Exception: WebSocket closed with status code: 1002 (null).

CarvalhoWesley opened this issue · 3 comments

version : signalr_core: ^1.1.1

final options = HttpConnectionOptions(
      accessTokenFactory: () async => "${_authFacade.token}",
      transport: HttpTransportType.webSockets,
      logging: (level, message) => print('$level: $message'),
    );
if (this.hubConnection == null) {
      this.hubConnection = HubConnectionBuilder()
          .withUrl(
            "$BASE_URL/v2/notificationHub",
            options,
          )
          .withAutomaticReconnect()
          .build();
}

Log

I/flutter ( 9907): LogLevel.debug: Sending handshake request.
I/flutter ( 9907): LogLevel.trace: (WebSockets transport) sending data. String data of length '32'.
I/flutter ( 9907): LogLevel.information: Using HubProtocol 'json'.
I/flutter ( 9907): LogLevel.trace: (WebSockets transport) socket closed.
I/flutter ( 9907): LogLevel.debug: HttpConnection.stopConnection(Exception: WebSocket closed with status code: 1002 (null).) called while in state ConnectionState.connected.
I/flutter ( 9907): LogLevel.error: Connection disconnected with error 'Exception: WebSocket closed with status code: 1002 (null).'.
I/flutter ( 9907): LogLevel.debug: HubConnection.connectionClosed(Exception: WebSocket closed with status code: 1002 (null).) called while in state HubConnectionState.connecting.
I/flutter ( 9907): LogLevel.debug: HttpConnection.stopConnection(null) called while in state ConnectionState.disconnected.
I/flutter ( 9907): LogLevel.debug: Call to HttpConnection.stopConnection(null) was ignored because the connection is already in the disconnected state.
I/flutter ( 9907): LogLevel.debug: Hub handshake failed with error 'Exception: WebSocket closed with status code: 1002 (null).' during start(). Stopping HubConnection.
I/flutter ( 9907): LogLevel.debug: Call to HttpConnection.stop(Exception: WebSocket closed with status code: 1002 (null).) ignored because the connection is already in the disconnected state.
I/flutter ( 9907): LogLevel.debug: HubConnection failed to start successfully because of error '{Exception: WebSocket closed with status code: 1002 (null)..toString()}'.
I/flutter ( 9907): Exception: WebSocket closed with status code: 1002 (null).

why using await connection.start() _CastError (type '_CastError' is not a subtype of type 'Exception' in type cast)

@CarvalhoWesley have you been able to fix this error?

@dynacorp and @dunghoang046 thanks for your attention. In fact, the error was my fault, because in my API (before .NET Core 3.1, now .NET 5) I was using an old SignalR package:

"aspnet-signalr@1.1.4"

which I believe is deprecated.

After switching to the package:

"@microsoft/signalr@5.0.7"

my problem has been resolved.

Here's a tip for legacy projects that use this first package mentioned by me.