OutWit.Communication.Client.WebSocket 2.0.1

dotnet add package OutWit.Communication.Client.WebSocket --version 2.0.1
                    
NuGet\Install-Package OutWit.Communication.Client.WebSocket -Version 2.0.1
                    
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="OutWit.Communication.Client.WebSocket" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OutWit.Communication.Client.WebSocket" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="OutWit.Communication.Client.WebSocket" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OutWit.Communication.Client.WebSocket --version 2.0.1
                    
#r "nuget: OutWit.Communication.Client.WebSocket, 2.0.1"
                    
#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.
#:package OutWit.Communication.Client.WebSocket@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OutWit.Communication.Client.WebSocket&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=OutWit.Communication.Client.WebSocket&version=2.0.1
                    
Install as a Cake Tool

OutWit.Communication.Client.WebSocket

WebSocket transport client for WitRPC, enabling real-time, full-duplex communication over WebSocket connections (great for internet or browser-based clients).

Overview

OutWit.Communication.Client.WebSocket allows a WitRPC client to connect to a server using the WebSocket protocol. WebSockets provide persistent, bi-directional communication over HTTP infrastructure, which is great for real-time updates and working through web proxies or firewalls. This transport is useful if you want a long-lived connection on standard web ports (like 80 or 443) or plan to interact with a server from web-based clients.

Like TCP, WebSocket supports full duplex communication, meaning the server can push events to the client at any time and the client can send requests anytime, all over a single persistent connection. WebSocket is essentially TCP tunneled through an HTTP handshake, making it friendly to web environments.

Use cases:

  • Communicating with a WitRPC server from a browser (with an appropriate JavaScript client, since browsers can do WebSocket). This can enable interactive web dashboards or controls that talk to a .NET service.

  • Situations where network infrastructure might block custom TCP ports but allows WebSocket (which often uses port 80 or 443 and can pass through proxies as it's seen as Web traffic).

  • Any scenario requiring real-time bidirectional messaging in a standardized way.

Note: Use OutWit.Communication.Server.WebSocket on the server side to accept WebSocket clients. Typically, the server is configured with an http:// (or https://) URL to listen on, and clients use the corresponding ws:// (or wss://) URL to connect.

Installation

Install-Package OutWit.Communication.Client.WebSocket

Usage

To use the WebSocket transport, configure the client with the WebSocket URI of the server:

using OutWit.Communication.Client;
using OutWit.Communication.Client.WebSocket;
using OutWit.Communication.Serializers;
using OutWit.Communication.Client.Encryption;

var client = WitClientBuilder.Build(options =>
{
    options.WithWebSocket("ws://localhost:5000/service"); // WebSocket endpoint URI
    options.WithJson();
    options.WithEncryption();   // optional: enable message encryption on top of WebSocket
    // options.WithAccessToken("SecureToken"); // if server requires a token
});
await client.ConnectAsync(TimeSpan.FromSeconds(5));

IMyService service = client.GetService<IMyService>();

In this example, the client will perform a WebSocket handshake to ws://localhost:5000/service. On the server side, you should have something like:

// Server-side (OutWit.Communication.Server.WebSocket):
options.WithWebSocket("http://localhost:5000/service", maxNumberOfClients: 10);

Notice that the server uses an http:// URL and the client uses ws://. The server's HTTP listener will upgrade incoming connections to WebSockets. If you want to secure the WebSocket with TLS, use an https:// URL on the server (with a valid certificate set up) and wss:// on the client. For example:

options.WithWebSocket("https://myserver.com/service", maxNumberOfClients: 10);

and on the client:

options.WithWebSocket("wss://myserver.com/service");

This will encrypt the WebSocket traffic. (In this case, you might not need WitRPC's own .WithEncryption(), since TLS already provides encryption.)

After connecting, usage of service is the same as always. You can call methods and receive events. The WebSocket stays open, allowing the server to send notifications spontaneously. The client will remain connected until you explicitly disconnect or dispose it, or a network issue occurs.

Token Authentication: If you set an access token on the server, the WebSocket client will include it when connecting (most likely as an HTTP header during the handshake). Be sure to call .WithAccessToken on the client with the correct token.

Performance: WebSockets have a bit more overhead at the start (the HTTP handshake), but after that, performance is comparable to raw TCP for most purposes. They are very suitable for applications with frequent message exchanges or needing low latency updates.

Further Documentation

See the official WitRPC documentation for additional examples and information on the WebSocket transport, including troubleshooting tips for WebSocket connections.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 63 7/5/2025
2.0.0 63 6/7/2025
1.2.0 102 2/28/2025
1.1.1 113 2/1/2025
1.1.0 112 1/25/2025
1.0.2 117 1/11/2025
1.0.0 115 1/2/2025