Giter VIP home page Giter VIP logo

primus.net's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.