websocket-client icon indicating copy to clipboard operation
websocket-client copied to clipboard

Blazor web assembly

Open dinos19 opened this issue 4 years ago • 1 comments

Hello, im trying to create a websocket and make a connection to remote server but there is something i dont get. the code that im using is

`var url = new Uri(urlString + connectparams); _client = new WebsocketClient(url); _client.ReconnectTimeout = TimeSpan.FromSeconds(120); _client.ErrorReconnectTimeout = TimeSpan.FromSeconds(30); _client.ReconnectionHappened.Subscribe(info => { Console.WriteLine($"Reconnection happened, type: {info.Type}, url: {_client.Url}"); Log($"Reconnected, type: '{info.Type}'", LogSeverity.Warning); StateHasChanged(); }); _client.DisconnectionHappened.Subscribe(info => { Console.WriteLine($"Disconnection happened, type: {info.Exception}"); Console.WriteLine($"Disconnected, type: '{info.Type}', reason: '{info.CloseStatus}'", LogSeverity.Warning); //Console.WriteLine($"Disconnected, type: '{info.ToString()}', reason: '{info.CloseStatus}'", LogSeverity.Warning); StateHasChanged(); });

    _client.MessageReceived.Subscribe(msg =>
    {
        Console.WriteLine($"Message received: {msg}");
        Log($"Received: '{msg.Text}'", LogSeverity.Info);
        StateHasChanged();
    });

    Console.WriteLine("Starting...");
    await _client.Start();
    //sendHello();
    Console.WriteLine("Started.");`

and the error im getting is

Disconnection happened, type: System.Net.WebSockets.WebSocketException (0x80004005): WebSocket connection failure. ---> System.Net.WebSockets.WebSocketException (0x80004005): An internal WebSocket error occurred. Please see the innerException, if present, for more details. at WebAssembly.Net.WebSockets.ClientWebSocket.ConnectAsyncJavaScript (System.Uri uri, System.Threading.CancellationToken cancellationToken) <0x31622c0 + 0x00442> in :0 at WebAssembly.Net.WebSockets.ClientWebSocket.ConnectAsyncJavaScript (System.Uri uri, System.Threading.CancellationToken cancellationToken) <0x31622c0 + 0x0048e> in :0 at System.Net.WebSockets.WebSocketHandle.ConnectAsyncCore (System.Uri uri, System.Threading.CancellationToken cancellationToken, System.Net.WebSockets.ClientWebSocketOptions options) <0x3140e30 + 0x001fe> in :0 at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore (System.Uri uri, System.Threading.CancellationToken cancellationToken) <0x314b9e0 + 0x0016a> in :0 at Websocket.Client.WebsocketClient+<>c.<.ctor>b__17_0 (System.Uri uri, System.Threading.CancellationToken token) <0x3131df8 + 0x000f2> in :0 at Websocket.Client.WebsocketClient.StartClient (System.Uri uri, System.Threading.CancellationToken token, Websocket.Client.ReconnectionType type, System.Boolean failFast) <0x31307d0 + 0x00116> in :0

dinos19 avatar Jan 06 '22 07:01 dinos19

Hi @dinos19,

are you using the latest version 4.4.43?

I was able to make it work in Blazor wasm, see project here: https://github.com/Marfusios/crypto-watcher-blazor

There was an issue with KeepAliveInterval that is not supported in wasm platform. So the latest version doesn't set KeepAliveInterval and leaves it to the default value.

Marfusios avatar Jan 06 '22 10:01 Marfusios