What is SignalR and how to use it?

ASP.NetServer Side ProgrammingProgramming

In typical web applications, the communication flow is one-way, i.e. from client to the server. The client initiates a request to the server, the server performs some task, and sends the response to the client.

SignalR is an open-source project that enables real-time, bi-directional web communication from server to clients. Using SignalR, you can write server-side code that can communicate with the clients instantly.

SignalR simplifies the process of adding real-time web functionality to web applications, where the server code pushes content to connected clients as soon as it becomes available. This frees the clients from repeatedly polling the server, and having the server wait for a client to request new data.

SignalR provides an API for creating server-to-client remote procedure calls (RPC) that call JavaScript code in the client browsers (and other client platforms) from server-side .NET code. SignalR also includes an API for connection management (for instance, connect and disconnect events), and grouping connections.

SignalR can be used to add any sort of "real-time" web functionality to your ASP.NET application. Any time a user refreshes a web page to see new data, or the page implements long polling to retrieve new data, it is a candidate for using SignalR.

SignalsR provides an application programming interface (API) using which you can create server-to-client remote procedure calls (RPC). These RPCs allow server side C# code to call JavaScript functions on the clients.

SignalR Uses Various Technologies

SignalR uses various technologies to handle real-time communication from server to client such as:

  • WebSockets

  • Server-Sent Events

  • Long Polling

It automatically selects the optimal transport method depending upon the capabilities of the server and clients.

Applications of SignalR

Although a chat is the common example used for SignalR, you can do a whole lot more. Here are some excellent applications of SignalR.

  • User notifications

  • Sending high-frequency updates to clients

  • Dashboards containing real-time charts and graphs

  • Collaborative applications, such as chat and messaging services

  • Games and entertainment applications

  • Alerting mechanisms

raja
Published on 22-Jun-2021 14:33:04
Advertisements