wstream 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package wstream --version 2.1.0                
NuGet\Install-Package wstream -Version 2.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="wstream" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add wstream --version 2.1.0                
#r "nuget: wstream, 2.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install wstream as a Cake Addin
#addin nuget:?package=wstream&version=2.1.0

// Install wstream as a Cake Tool
#tool nuget:?package=wstream&version=2.1.0                

WStream - WebSocket Streams

WStream offers a simple and high-performance WebSocket stream built on top of Kestrel

Use Cases:

  • Server-to-Server communication.
  • Sending binary data through web proxies like Cloudflare.
  • Building custom protocols.
  • Writing micro websocket servers without too much boilerplate.
  • Bypassing TCP filters through a firewall.

Wow, that sounds great! How do I use WStream?

Usage

WStream offers three main constructs, WsClient, WsServer and WsStream.

Here is a simple example of a ping program built in WStream.

// create the server
var server = new WsServer();
await server.StartAsync(new IPEndPoint(IPAddress.Any, 8080), async stream =>
{
    // called when a client connects
    await stream.WriteAsync(BitConverter.GetBytes(DateTime.Now.ToBinary()));
    await stream.CloseAsync();
});

// start client
var client = new WsClient();
var connection = await client.ConnectAsync(new Uri("ws://localhost:8080"));
// read data
var binReader = new BinaryReader(connection);
Console.WriteLine($"Current time is {DateTime.FromBinary(binReader.ReadInt64())}");

// cleanup
client.Dispose();
server.Dispose();

Advanced Usage

WStream also supports extending the existing stream. You are able to overload the underlying websocket with custom behaviour like compression or encryption.

An example usage of this API is shown in the samples project.

Performance

WStream was built with performance in mind.

Here is a benchmark performed on Windows 10 Build 19402 with a core i7-6700k and 32gb of system ram.

Buffer Size: 65536  Throughput: 558.92 MBps  Elapsed: 00:15:16.0470650  Message Rate: 8,942.77 msg/s  Payload Size: 511,999.00 MB.

As you can see, WStream reaches over 4 Gbps through a single connection!

Current Limitations

Due to the fact that Kestrel is bundled inside of ASP.NET Core, there are a large number of dependencies. There is currently no way around this 😦

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on wstream:

Package Downloads
wstream.Crypto

Provides experimental crypto for wstream

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.4 434 11/13/2021
2.1.3 435 11/7/2021
2.1.2 329 11/2/2021
2.1.1 330 11/2/2021
2.1.0 510 5/31/2021
2.0.0 372 5/31/2021