Rewrite of primus server in .NET Core
Original repository : https://github.com/primus/primus
- First of all, add a reference of the lib to your ASP.Net Core project.
(For next steps, you can check the Example ASP.Net core project, to avoid misunderstandings !)
- Add this line in your
ConfigureServices
method inStartup.cs
. It permits to load the native routes of primus inside the lib
services.AddMvc().AddApplicationPart(typeof(PrimusController).Assembly).AddControllersAsServices();
- Add this line in your
Configure
method inStartup.cs
. for loading the handlers which is for the data received from the websocket in
MessageParser.Initialize();
- Add those lines in your
Configure
method inStartup.cs
aboveapp.UseRouting();
. to let Kestrel manage the websocket connections
app.UseWebSockets(new WebSocketOptions()
{
//KeepAliveInterval is not necessary, can be removed or modified
KeepAliveInterval = TimeSpan.FromSeconds(120)
});
- Add this line in your
Configure
method inStartup.cs
aboveapp.UseRouting();
and afterapp.UseWebSockets();
. to handle a WebsocketRequest because the communication is initiating in a Task
app.UseMiddleware<WebSocketMiddleware>();
- Enjoy !
In the ClientManager.cs
class there is a static event called OnClientCreated, you can add your method to the event to get all PrimusClient
object created.
In the ClientManager.cs
class there is a static event called OnClientDisconnected, you can add your method to the event to get all PrimusClient
object disconnected.
In the PrimusClient.cs
class there is an event to handle the data received from the webSocket per client.