https://github.com/timostamm/aspnetcore-websocket-controller
Easy WebSockets for AspNetCore 3.0
https://github.com/timostamm/aspnetcore-websocket-controller
aspnetcore3 websocket
Last synced: 18 days ago
JSON representation
Easy WebSockets for AspNetCore 3.0
- Host: GitHub
- URL: https://github.com/timostamm/aspnetcore-websocket-controller
- Owner: timostamm
- License: mit
- Created: 2019-10-30T17:53:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-04T20:41:30.000Z (over 6 years ago)
- Last Synced: 2025-07-31T07:16:14.993Z (11 months ago)
- Topics: aspnetcore3, websocket
- Language: C#
- Size: 14.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
aspnetcore-websocket-controller
===============================
Easy WebSockets for AspNetCore 3.0.
Run `dotnet add package TimoStamm.WebSockets.Controller` to install.
Implement your websocket controller:
````c#
public class MyController : AWebsocketController
{
public override async Task OnOpen(Client client)
{
await client.SendAsync("Hello there");
}
// OnTextMessage(Client client, string text)
// OnBinaryMessage(...)
// OnClose(...)
}
````
And add it in your `Startup.cs`
````c#
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseWebSockets();
var myHandler = WebSocketHandler.CreateFor(app.ApplicationServices);
app.Run(myHandler.HandleRequest);
}
````
See example for a basic websocket chat. To run, `cd example` and `dotnet run`, then open http://localhost:5000/