Let’s first understand what is SignalR?

In simple words I will say “SignalR is an Abstraction that intelligently decides how to enable real time over HTTP.” SignalR can figure out what a server and client can do. It provides you the capability to actually establish a persistent connection between client and server and lets server communicate with client seamlessly. AJAX allows us to send a request (relatively very small) and update the UI based on the response. Challenges we face include the different behavior of browsers in terms of features and support. From a performance point of view, the server’s resource and network utilization are other issues, so we can’t blindly send multiple requests to the server. Similarly we can’t make the user wait more while waiting for the update. It’s developer’s responsibility to use the best available option/protocol for handling real-time communication.SignalR is one of the best way for real-time communication.

I will be bad blogger if I just keep on writing about SignalR without any practical code on this so let me start with creating a small application “Hitcounter” You might have done this many a times before in simple javascript. In this we will get the active users on the site.

Follow these steps

You can see there are many packages available for SignalR.SignalR guys have divided the component into small package.We will install asp.net SignalR.

[HubName("hitCounter")]
by this I am giving a simple name to HitCounterHub class,by this simple name I will call my Hub class from client side.

SignalR.

Client Side Implementation.

Now you can see the SignalR methods like hubConnection

SignalR.

The below code will invoke the recordHit method from our Hub class.

con.start(function () {
hub.invoke('recordHit');
});

SignalR.
That is all we need to do for now.

Now when you will run this application it will shown 1 as hitCount. Open the same url in different browser or on different window it will change the hitCount in real time

SignalR.
Now we are done with our first simple SignalR application.
Hope it will be useful for you.