Signal R Simplified
It’s been long I have been searching for a good and working Signal-R blog, but trust me there are none. Some are marginally good but again, the code they offer does not work. After lot of concept seeking and code searching I finally able to create a working demo. In this blog post, we will go step by step on understanding of Signal-R.
What is Signal-R
If client needs data from server, it simply pings server and ask for data. But there are case when client need to constantly ping server to see if server has any data of it’s interest, if yes, client fetches the data and if no, it will ping the server again. Let’s not get confused on this, let’s go through an example to rather simplify the situation.
Imagine your mom ask you to bring some groceries back home when you return. You know Moms are so impatient, and you can trust on that. On the same evening, when you are on the way back she would continuously ring you and remind you that you need to purchase groceries, you need to purchase groceries, you need to purchase groceries…You can say yes to any one of the call if you have bought it already, else your answer would be no.
Consider the same scenario where instead of your Mom, your Dad has given you same task. He won’t ping you constantly to inspect whether or not you are done, but instead you have to call him back once you are done purchasing.
In the above analogy, if you consider yourself a server and your parents as Client, the later communication with Dad is called as duplex communication and the former with Mom is simplex communication. In duplex communication, not only client can ask server for data, server could also ping its client with the set of data it has.
There are various other techniques you can use to attain this, in this blog however, we would be focusing on the aspects of Signal-R.
Signal-R getting started
To get started, we need to first create an empty ASP.Net website and here we go.

Once the Web Site is created, go to solution explorer –> Right click on project and choose "Manage Nuget Package".

When the Packet manager Window is opened search for the signal-r package.

Install the Microsoft ASP.NET SignalR package. When the Visual Studio is done installing the package, you are good to go.
Add two classes and one HTML page after that in the solution.
- ChatHub.cs
- Startup.cs
- index.html
ChatHub Class
This is what I have in my class:
- 1: using Microsoft.AspNet.SignalR;
- 2: using System;
- 3: using System.Collections.Generic;
- 4: using System.Linq;
- 5: using System.Threading;
- 6: using System.Web;
- 7:
- 8: namespace MySignalRDemo
- 9: {
- 10: public class ChatHub : Hub
- 11: {
- 12: /// <summary>
- 13: /// Send the value to the server after every two seconds
- 14: /// </summary>
- 15: public void Send()
- 16: {
- 17: // Call the broadcastMessage method to update clients.
- 18: for (int i = 0; i <= 100; i++)
- 19: {
- 20: //"All" is dynamic, and broadcastMessage is the method that we'll
- 21: //create in JavaScript at client side.
- 22: Clients.All.broadcastMessage(i.ToString());
- 23: Thread.Sleep(2000);
- 24: }
- 25: }
- 26: }
- 27: }


Pradeep SPosted Nov 2, 2020, 4:03 AM
Good article. When counter goes from 0..100 and if I refresh browser then it shows broadcast message from both the call i.e it shows 12..1..13..2..14..3 and so on. How to avoid broadcast message from old call and show only from latest call. Thanks
Umair HassanPosted Mar 9, 2018, 4:04 AM
Appreciate your work! But dont copy paste.
avinash bhujanPosted Dec 26, 2016, 5:31 AM
Copycat! You have not created a working demo but copied it from here: https://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr
Umamaheswara Rao DasariPosted Jun 22, 2016, 9:24 AM
Yes...u r a good teacher. Very interesting article.
Mohammad KhalidPosted May 27, 2015, 10:25 AM
Very good article...You are a good teacher
Santhakumar MunuswamyPosted Apr 25, 2015, 7:31 AM
Thanks for nice article
Rajeev RanjanPosted Sep 26, 2014, 7:18 AM
such a good article.. we wish you can write some more article on SignalR . I am really new for SignalR , and trying to learn more
Pankaj BajajPosted May 8, 2014, 1:06 AM
nice introduction