Monday, 26 August 2013


SignalR .net

In this post I am sharing magical stuff which I have learned recently and it will be very useful..Let's dive!!!

SignalR is a groundbreaking open-source project from .NET community. It offers real-time communication to a variety of platforms, is easy to use and to set up, and scales immensely.

Initially it was developed for and later it was scaled to Silverlight and WPF technologies for real time notification/Push mechanism.Pushing data from the server to the client (not just browser clients) has always been a tough problem. SignalR makes it dead easy and handles all the heavy lifting for you.

What is ASP.NET SignalR?

ASP.NET SignalR is a new library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. What is "real-time web" functionality? It's the ability to have your server-side code push content to the connected clients as it happens, in real-time.

You may have heard of WebSockets, a new HTML5 API that enables bi-directional communication between the browser and server. SignalR will use WebSockets under the covers when it's available, and gracefully fallback to other techniques and technologies when it isn't, while your application code stays the same.

SignalR also provides a very simple, high-level API for doing server to client RPC (call JavaScript functions in your clients' browsers from server-side .NET code) in your ASP.NET application, as well as adding useful hooks for connection management, e.g. connect/disconnect events, grouping connections, authorization.

What can you do with ASP.NET SignalR?

SignalR can be used to add any sort of "real-time" web functionality to your ASP.NET application. While chat is often used as an example, you can do a whole lot more. Any time a user refreshes a web page to see new data, or the page implements Ajax long polling to retrieve new data, is candidate for using SignalR.

It also enables completely new types of applications, that require high frequency updates from the server, e.g. real-time gaming. ShootR game is a great example

For more information and about the latest news you can go to SignalR.

I have did a beginning hands on code which was inspired from the instruction video.The example is to move a rectangular shape in one client and that has to reflect in all the connected clients(browser).The server and the client side code are in the same project.Client code will be in Javascript file and Server code is in C#.Before trying out the sample please install the SignalR package into your project.To install SignalR refer Getting SignalR-Ready.

Step 1:

Create a new empty web application and Right click the project and click Manage NuGet Packages.Then search for SignalR and install the ASP.Net SignalR sample now the sample stockticker application will be downloaded into your application and that will compile successfully and now create a folder MoveShapeDemo and create the 3 files as shown in the second image.

Manage Nuget Package

MoveShapeDemo Files

Step 2:

Now you can code your server side code in MoveShape.cs file as show in the image below.Please see the comment in the code for your better understanding.

Step 3:

Now you can code your client side code in MoveShape.js file as show in the image below.
Please see the comment in the code for your better understanding.

Step 4 :

Now you can code you view(HTML) page in MoveShape.htm file as show in the image below.
Please see the comment in the code for your better understanding.

That's you can run your application in browser (IE > 8) at least 2 browser and then try it by moving the square in one browser and that should reflect in the other clients(browsers) too.

Hope you enjoyed this post.

Thanks for Reading.Happy Coding!!


  1. Good Article on ASP.NET SignalR

  2. Excellent article... It give a simple and good understanding on what we can do with the help of "SignalR"

  3. Very Good article for beginners. The demo explained is good. Thanks.

  4. nice and informative article and also a very helpful.