Skip to content

timostamm/aspnetcore-websocket-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aspnetcore-websocket-controller

Easy WebSockets for AspNetCore 3.0.

Run dotnet add package TimoStamm.WebSockets.Controller to install.

Implement your websocket controller:

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

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseWebSockets();
    var myHandler = WebSocketHandler.CreateFor<MyController>(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/

About

Easy WebSockets for AspNetCore 3.0

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy