Cyaim.WebSocketServer
1.5.2
See the version list below for details.
dotnet add package Cyaim.WebSocketServer --version 1.5.2
NuGet\Install-Package Cyaim.WebSocketServer -Version 1.5.2
<PackageReference Include="Cyaim.WebSocketServer" Version="1.5.2" />
paket add Cyaim.WebSocketServer --version 1.5.2
#r "nuget: Cyaim.WebSocketServer, 1.5.2"
// Install Cyaim.WebSocketServer as a Cake Addin
#addin nuget:?package=Cyaim.WebSocketServer&version=1.5.2
// Install Cyaim.WebSocketServer as a Cake Tool
#tool nuget:?package=Cyaim.WebSocketServer&version=1.5.2
WebSocketServer
Version | NuGet | Build | Code Size | License |
---|---|---|---|---|
WebSocketServer is lightweight and high performance WebSocket library.support route, full duplex communication.
QuickStart
- Install library
Install-Package Cyaim.WebSocketServer -Version 1.5.1 2. Configure middleware
- Configure websocket route
services.ConfigureWebSocketRoute(x =>
{
//Define channels
x.WebSocketChannels = new Dictionary<string, WebSocketRouteOption.WebSocketChannelHandler>()
{
{ "/ws",new WebSocketChannelHandler().MvcChannelHandler}
};
});
- Configure middleware
var webSocketOptions = new WebSocketOptions()
{
KeepAliveInterval = TimeSpan.FromSeconds(120),
ReceiveBufferSize = 4 * 1024
};
app.UseWebSockets(webSocketOptions);
app.UseWebSocketRoute(app.ApplicationServices);
- 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
{
"Status": 0,
"Msg": null,
"RequestTime": 637395762382112345,
"ComplateTime": 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:
- 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();
}
- 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
{
"Status": 0,
"Msg": null,
"RequestTime": 0,
"ComplateTime": 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 | Versions 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 | 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. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.9)
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.9)
- Newtonsoft.Json (>= 12.0.3)
- Websocket.Client (>= 4.3.21)
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 | |
---|---|---|---|
1.7.1 | 77 | 5/31/2024 | |
1.7.0 | 94 | 5/30/2024 | |
1.6.4 | 70 | 5/21/2024 | |
1.6.3 | 82 | 5/16/2024 | |
1.6.2 | 96 | 5/15/2024 | |
1.6.1 | 96 | 5/15/2024 | |
1.6.0 | 309 | 11/25/2022 | |
1.5.9 | 301 | 11/20/2022 | |
1.5.8 | 435 | 12/30/2020 | |
1.5.7 | 388 | 12/25/2020 | |
1.5.6 | 345 | 12/3/2020 | |
1.5.5 | 337 | 11/12/2020 | |
1.5.4 | 378 | 11/12/2020 | |
1.5.3 | 379 | 11/11/2020 | |
1.5.2 | 376 | 11/10/2020 | |
1.5.1 | 408 | 10/30/2020 | |
1.5.0 | 413 | 10/30/2020 | |
1.0.0 | 361 | 10/29/2020 |
1.Fix some problems