AUser123
AUser123

Reputation: 731

What is the difference between using Kestrel Server or SignalR Server in ASP.NET Core?

As far as my understanding, SignalR allows you to add real-time functionality to web applications by allowing “server to client” and “client to server” communication. It runs on a specified port, which can be used for communication.Hubs need to be created with functions to be called. Krestel server is a type of minified IIS server, which also runs in a given port and client application can connect to that port.

So, my question is what is the difference between using SignalR or Krestel server, since both run on given port and client applications connect to that port?

Upvotes: 1

Views: 1792

Answers (2)

Marco Vargas
Marco Vargas

Reputation: 1337

Remember that the idea of all frameworks is to encapsulate complexity!

Kestrel is the default, cross-platform Web server implementation that Microsoft implemented in the ASP.NET Core framework, just as Tomcat is the default on Spring Framework for Java.

enter image description here More Info here

Kestrel, as a Web Server, handle traffic coming from outside to your app through http, and in the case of SignalR it also handles traffic bidirectional through webSockets, and it also can handle http/2 and others.

Remember that WebSockets is a different protocol on layer 7 just like http or https, websockets go through ws or wss these are also managed by a web server like Kestrel.

This being said, SignalR is just a library, part of the ASP.NET Core framework to handle WebSockets and other types of connections, making it easier for you as developer to build applications, abstracting all the complexity of:

  1. a Web Server (Using Kestrel)
  2. WebSockets (Using SignalR)

More info here

Upvotes: 4

Brando Zhang
Brando Zhang

Reputation: 28267

As Andy says, the Signalr is a kind of service which running on the kestrel. In my opinion, it is a web framework like MVC or web api.

We will add the Signalr like a service as MVC , Razor Pages and add its routes like below:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
        services.AddSignalR();
    }

Endpoint:

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapRazorPages();
            endpoints.MapHub<UserActivityHub>("/active");
        });

The kestrel is a webserver, which is used to host the core application. It will listen for HTTP requests and surfaces them to the app as a set of request features composed into an HttpContext. Details about kestrel server ,you could refer to this article.

Upvotes: 1

Related Questions