Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
/ Primus.NET Public archive

Rewrite of primus server in .NET Core 3.1

Notifications You must be signed in to change notification settings

Aberion-e/Primus.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Primus.NET

Rewrite of primus server in .NET Core

Original repository : https://github.com/primus/primus

How to use Primus.NET in a ASP.Net Core project

  1. 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 !)

  1. Add this line in your ConfigureServices method in Startup.cs. It permits to load the native routes of primus inside the lib
services.AddMvc().AddApplicationPart(typeof(PrimusController).Assembly).AddControllersAsServices();
  1. Add this line in your Configure method in Startup.cs. for loading the handlers which is for the data received from the websocket in
MessageParser.Initialize();
  1. Add those lines in your Configure method in Startup.cs above app.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)
});
  1. Add this line in your Configure method in Startup.cs above app.UseRouting(); and after app.UseWebSockets();. to handle a WebsocketRequest because the communication is initiating in a Task
app.UseMiddleware<WebSocketMiddleware>();
  1. Enjoy !

Events

OnClientCreated

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.

OnClientDisconnected

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.

DataReceived

In the PrimusClient.cs class there is an event to handle the data received from the webSocket per client.

Releases

No releases published

Packages

No packages published