Cyaim.WebSocketServer 1.7.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Cyaim.WebSocketServer --version 1.7.4
                    
NuGet\Install-Package Cyaim.WebSocketServer -Version 1.7.4
                    
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="Cyaim.WebSocketServer" Version="1.7.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cyaim.WebSocketServer" Version="1.7.4" />
                    
Directory.Packages.props
<PackageReference Include="Cyaim.WebSocketServer" />
                    
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 Cyaim.WebSocketServer --version 1.7.4
                    
#r "nuget: Cyaim.WebSocketServer, 1.7.4"
                    
#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 Cyaim.WebSocketServer@1.7.4
                    
#: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=Cyaim.WebSocketServer&version=1.7.4
                    
Install as a Cake Addin
#tool nuget:?package=Cyaim.WebSocketServer&version=1.7.4
                    
Install as a Cake Tool

WebSocketServer

996ICU Version NuGet Build Code Size License
996.icu alternate text is missing from this package README imagealternate text is missing from this package README image alternate text is missing from this package README imageNuGet alternate text is missing from this package README image Code size LicenseLICENSE

WebSocketServer is lightweight and high performance WebSocket library.Support route, full duplex communication.

QuickStart

  1. Install library

Install-Package Cyaim.WebSocketServer 2. Configure middleware

  • Configure websocket route
services.ConfigureWebSocketRoute(x =>
{
    //Define channels
    x.WebSocketChannels = new Dictionary<string, WebSocketRouteOption.WebSocketChannelHandler>()
    {
        { "/ws",new MvcChannelHandler(4*1024).ConnectionEntry}
    };
    x.ApplicationServiceCollection = services;
});
  • Configure middleware
var webSocketOptions = new WebSocketOptions()
{
    KeepAliveInterval = TimeSpan.FromSeconds(120),

    // This configuration has been deprecated
    ReceiveBufferSize = 4 * 1024
};
app.UseWebSockets(webSocketOptions);
app.UseWebSocketServer();
  • Minimal API can be use
builder.Services.ConfigureWebSocketRoute(x =>
{
    //Define channels
    x.WebSocketChannels = new Dictionary<string, WebSocketRouteOption.WebSocketChannelHandler>()
    {
        { "/ws",new MvcChannelHandler(4*1024).ConnectionEntry}
    };
    x.ApplicationServiceCollection = builder.Services;
});

var webSocketOptions = new WebSocketOptions()
{
    KeepAliveInterval = TimeSpan.FromSeconds(120),
};
app.UseWebSockets(webSocketOptions);
app.UseWebSocketServer();
  1. Mark WebSocket Endpoints
    • Go to Controller → Action
    • Add attribute [WebSocket]

[WebSocket] → "method" parameter ignore case

Example Code:

// mark WebSocket 
[WebSocket()]
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
    var rng = new Random();
    return Enumerable.Range(1, 2).Select(index => new WeatherForecast
    {
         Date = DateTime.Now.AddDays(index),
         TemperatureC = rng.Next(-20, 55),
         Summary = Summaries[rng.Next(Summaries.Length)]
    }).ToArray();
}

Request and Response

Scheme namespace 👇
Request Cyaim.WebSocketServer.Infrastructure.Handlers.MvcRequestScheme
Response Cyaim.WebSocketServer.Infrastructure.Handlers.MvcResponseScheme

Request target ignore case

Request scheme

1. Nonparametric method request

{
	"target": "WeatherForecast.Get",
	"body": {}
}

This request will be located at "WeatherForecastController" → "Get" Method.

Response to this request

{
	"Target": "WeatherForecast.Get"
	"Status": 0,
	"Msg": null,
	"RequestTime": 637395762382112345,
	"CompleteTime": 637395762382134526,
	"Body": [{
		"Date": "2020-10-30T13:50:38.2133285+08:00",
		"TemperatureC": 43,
		"TemperatureF": 109,
		"Summary": "Scorching"
	}, {
		"Date": "2020-10-31T13:50:38.213337+08:00",
		"TemperatureC": 1,
		"TemperatureF": 33,
		"Summary": "Chilly"
	}]
}

Forward invoke method return content will write MvcResponseScheme.Body.

2. Request with parameters

Example Code:

  1. Change method code to:
[WebSocket]
[HttpGet]
public IEnumerable<WeatherForecast> Get(Test a)
{
    var rng = new Random();
    return Enumerable.Range(1, 2).Select(index => new WeatherForecast
    {
         TemperatureC = a.PreTemperatureC + rng.Next(-20, 55),
         Summary = a.PreSummary + Summaries[rng.Next(Summaries.Length)]
    }).ToArray();
}
  1. Define parameter class
public class Test
{
    public string PreSummary { get; set; }
    public int PreTemperatureC { get; set; }
}

Request parameter

{
	"target": "WeatherForecast.Get",
	"body": {
	    "PreSummary":"Cyaim_",
	    "PreTemperatureC":233
	}
}

Request body will write invoke method parameter.

Response to this request

{
	"Target": "WeatherForecast.Get"
	"Status": 0,
	"Msg": null,
	"RequestTime": 0,
	"CompleteTime": 637395922139434966,
	"Body": [{
		"Date": "0001-01-01T00:00:00",
		"TemperatureC": 282,
		"TemperatureF": 539,
		"Summary": "Cyaim_Warm"
	}, {
		"Date": "0001-01-01T00:00:00",
		"TemperatureC": 285,
		"TemperatureF": 544,
		"Summary": "Cyaim_Sweltering"
	}]
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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 (7)

Showing the top 5 NuGet packages that depend on Cyaim.WebSocketServer:

Package Downloads
Cyaim.WebSocketServer.Cluster.Hybrid

WebSocketServer Hybrid cluster transport extension (Redis for service discovery, RabbitMQ for message routing) WebSocketServer 混合集群传输扩展(Redis 用于服务发现,RabbitMQ 用于消息路由) Supports different Redis and RabbitMQ libraries through abstraction layer 通过抽象层支持不同的 Redis 和 RabbitMQ 库

Cyaim.WebSocketServer.MessagePack

WebSocketServer MessagePack binary protocol extension WebSocketServer MessagePack 二进制协议扩展

Cyaim.WebSocketServer.Dashboard

WebSocketServer Dashboard for monitoring and managing WebSocket server and cluster WebSocketServer 仪表板,用于监控和管�?WebSocket 服务器和集群

Cyaim.WebSocketServer.Cluster.FreeRedis

WebSocketServer FreeRedis cluster transport extension WebSocketServer FreeRedis 集群传输扩展

Cyaim.WebSocketServer.Cluster.StackExchangeRedis

WebSocketServer Redis cluster transport extension using StackExchange.Redis WebSocketServer Redis 集群传输扩展(基于 StackExchange.Redis)

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.26.1021.1621 396 10/21/2026
2.26.1021.1015 382 10/21/2026
2.25.1205.1023 618 12/5/2025
2.25.1205.945 553 12/5/2025
2.25.1205.901 546 12/5/2025
2.25.1205.706 556 12/5/2025
2.25.1205.558 557 12/5/2025
2.25.1205.525 543 12/5/2025
2.25.1204.141 551 12/4/2025
2.25.1203.534 1,028 12/3/2025
2.25.1202.1527 1,025 12/2/2025
2.25.1202.1149 1,026 12/2/2025
2.25.1202.716 1,060 12/2/2025
2.25.1201.1539 858 12/1/2025
1.7.8 1,146 10/20/2024
1.7.7 227 10/16/2024
1.7.6 191 10/16/2024
1.7.5 194 10/14/2024
1.7.4 208 10/14/2024 1.7.4 is deprecated because it has critical bugs.
1.7.3 591 8/22/2024 1.7.3 is deprecated because it has critical bugs.
Loading failed

fix: serious error.