jamiewest / signalr_core

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

WebSocket closed with status code: 1002 #82

Closed wolnynick closed 7 months ago

wolnynick commented 2 years ago

Hi, I'm trying to make connection with HUB and default transport setting is throwing error with 1002 code. Why do I need to set up transport: HttpTransportType.serverSentEvents ? It shouldn't be managed automatically by library by chosing the best option? Or maybe there is possibility to achieve it?

    connection = HubConnectionBuilder()
        .withUrl(
          'https://url/hub/chat',
          HttpConnectionOptions(
            // transport: HttpTransportType.serverSentEvents, (Only when I uncomment this line then I can make connection)
            logging: (level, message) => print('test: $message'),
          ),
        )
        .build();

    await connection.start();

Error without transport: HttpTransportType.serverSentEvents:

Starting HubConnection.
Starting connection with transfer format 'TransferFormat.text'.
Sending negotiation request: https://url/hub/chat/negotiate.
Selecting transport 'HttpTransportType.webSockets'.
(WebSockets transport) Connecting.
WebSocket connected to wss://url/hub/chat?id=ARXbK9CjBkJjxWPSAHTzHg.
The HttpConnection connected successfully.
Sending handshake request.
(WebSockets transport) sending data. String data of length '32'.
Using HubProtocol 'json'.
(WebSockets transport) socket closed.
HttpConnection.stopConnection(Exception: WebSocket closed with status code: 1002 (null).) called while in state ConnectionState.connected.
Connection disconnected with error 'Exception: WebSocket closed with status code: 1002 (null).'.
HubConnection.connectionClosed(Exception: WebSocket closed with status code: 1002 (null).) called while in state HubConnectionState.connecting.
HttpConnection.stopConnection(null) called while in state ConnectionState.disconnected.
Call to HttpConnection.stopConnection(null) was ignored because the connection is already in the disconnected state.
 Hub handshake failed with error 'Exception: WebSocket closed with status code: 1002 (null).' during start(). Stopping HubConnection.
Call to HttpConnection.stop(Exception: WebSocket closed with status code: 1002 (null).) ignored because the connection is already in the disconnected state.
HubConnection failed to start successfully because of error '{Exception: WebSocket closed with status code: 1002 (null)..toString()}'
minhnhatvdl commented 2 years ago

I have the same problème. Anyone can explain me why ?

misici234 commented 2 years ago

The reason is a bug in the package. I reported it more than a year ago, see https://github.com/jamiewest/signalr_core/issues/38. If you want to make it work then fix it yourself and submit a pull request here. Thanks.

Invectys commented 2 years ago

This error occurs when name to hub is incorrect