Sitelet https://github.com/unoplatform/Uno.Wasm.WebSockets
Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.
unoplatformPublic archive

About

An Uno Platform implementation of .NET System.Net.WebSocket for WebAssembly

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

10 stars

Watchers

14 watching

Forks

Latest commit

 

History

43 Commits

Folders and files

Repository files navigation

Notice

This repository is now deprecated, as the support for ClientWebSocket is included in .NET 6 for WebAssembly.

Uno.Wasm.WebSockets

Uno.Wasm.WebSockets is a concrete implementation of the System.Net.WebSocket class for WebAssembly, named Uno.Wasm.WebSockets.WasmWebSocket.

This package requires the use of the Uno.Wasm.Bootstrap package to work properly.

Sample applications

Try WebSockets from .NET code live here: https://websockets-wasm.platform.uno

The sample applications use the Uno Platform and are built to use WebSockets in their respective platforms. The WebAssembly one uses Uno.Wasm.WebSockets.WasmWebSocket.

Open [Uno.Wasm.WebSockets.sln] to discover the sample, in the WasmWebSocketsSample.Shared project.

How to use the WasmWebSocket class

Given a project that already references Uno.Wasm.Bootstrap, add the Uno.Wasm.WebSockets nuget package, and write the following:

var ws = new Uno.Wasm.WebSockets.WasmWebSocket();

// Connect to a simple echo WebSocket server
await ws.ConnectAsync(new Uri("wss://echo.websocket.org"), CancellationToken.None);

Console.WriteLine("Program: Connected!");

// Send some data
var data = new ArraySegment<byte>(Encoding.UTF8.GetBytes("Hello websocket !"));
await ws.SendAsync(data, System.Net.WebSockets.WebSocketMessageType.Binary, false, CancellationToken.None);

Console.WriteLine("Program: Sent!");

// Read the echo back
var buffer = new byte[1024];
var received = await ws.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);

var receivedString = Encoding.UTF8.GetString(buffer, 0, received.Count);
Console.WriteLine($"Received {received.Count} bytes: {receivedString}");

About

An Uno Platform implementation of .NET System.Net.WebSocket for WebAssembly

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

10 stars

Watchers

14 watching

Forks

Releases

Packages

Used by

Contributors

Languages