Get started with Cyaim.WebSocketServer in 5 minutes.
dotnet add package Cyaim.WebSocketServerdotnet new web -n WebSocketServerApp
cd WebSocketServerAppdotnet add package Cyaim.WebSocketServerusing Cyaim.WebSocketServer.Infrastructure.Handlers.MvcHandler;
using Cyaim.WebSocketServer.Infrastructure.Configures;
var builder = WebApplication.CreateBuilder(args);
// Configure WebSocket route
builder.Services.ConfigureWebSocketRoute(x =>
{
x.WebSocketChannels = new Dictionary<string, WebSocketRouteOption.WebSocketChannelHandler>()
{
{ "/ws", new MvcChannelHandler().ConnectionEntry }
};
x.ApplicationServiceCollection = builder.Services;
});
builder.Services.AddControllers();
var app = builder.Build();
app.UseWebSockets();
app.UseWebSocketServer();
app.MapControllers();
app.Run();using Cyaim.WebSocketServer.Infrastructure.Attributes;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("[controller]")]
public class EchoController : ControllerBase
{
[WebSocket]
[HttpGet]
public string Echo(string message)
{
return $"Echo: {message}";
}
}dotnet runConnect to ws://localhost:5000/ws using a WebSocket client and send:
{
"target": "Echo.Echo",
"body": {
"message": "Hello, WebSocket!"
}
}- Read Core Library Documentation for detailed features
- Check Configuration Guide for configuration options
- Refer to sample projects for practical applications