In previous ASP.NET app development process, HTTP convention was the basis for all communications over the web and it has helped in our technical needs. HTTP works in a request and response model, where a request needs to be sent to the server to get any updates. This becomes a challenge in situations where we require continuous data for wherein when a client opens a page of a website then it should be updated with corresponding change on the server. However, according to the HTTP architecture, a new request must be sent to get an update from the server. Let’s take a real-time example to get a clear idea, to check the scores you visit Football website, where you sometimes see the page gets refreshed for a second and many times you see the score is not updated. To overcome this situation Microsoft has introduced new API called “SignalR“.
SignalR is a library for developers that improves the procedure of adding real-time web functionality in the applications. Real-time web functionality is the ability to have server code push content to associated clients instantly as it becomes accessible, rather than having the server to wait for a client to request new data. It is not necessary for it to be hosted in ASP.NET, it can be either self-hosted or hosted using Open Web Interface for .NET (OWIN).
SignalR uses multiple technologies to set up communications between client and server. There are four primary mechanisms on which SignalR work.
This provides a genuine two-way communication over a single TCP connection on the web. If Client and Server support web socket then this creates a persistent connection between them which can be utilized by either client or server to send the data anytime. This is a very effective approach since it utilizes less memory, and demonstrates the most minimal inactivity.
This method is presented with HTML5 which permits the server to push the updates to the client at whatever point new data is available. This technology is used when Web Socket is not supported.
It is part of the COMET model which uses a hidden iframe on the browser to receive the data in an incremental manner from the server. Server begins sending the information in a series of chunks without knowing the complete length of the content.
It is also a part of the COMET model, and keeps polling the server to check for updates. AJAX based request is sent to the server to minimize the resource usage and provide a better user experience.
SignalR provides two modes for communicate between clients and servers.
Persistent Connections gives direct access to a lower-level communication protocol that signalR exposes. Every client connection with a server is recognized by a connectionID. This API uses the format of the authentic message sent that needs to be specified if the developer wants to work with messaging and dispatching model rather than a remote invocation.
A Hub gives multicast functionality over a WebSocket connection. At the point when any client sends a message to the Hub, it shows the message to all the associated clients and makes a connection between them which is known as a Client-Hub Connection.
SignalR provides cross-platform libraries which can be used in conjunction with iOS App, Android App & Windows App development with an ASP.NET server component. This makes SignalR flexible, as well as simple and effective. Since SignalR is introduced, many difficult business structures that require the real-time communication are being resolved within few lines of codes. Additionally, it is worth to specify that most recent and upgraded versions of browsers have a lot of impact for such revolution.
WRITTEN BY: Parth Patel
Parth Patel is a Microsoft Certified Solution Associate (MCSA) and DotNet Team Lead at CMARIX, a leading Asp.net mvc development company. With 10+ years of…
FEW MORE POSTS BY Parth Patel: