There are already some good walkthroughs about this on the SignalR github site (https://github.com/SignalR/SignalR) so as a warm-up I suggest you take a look at those. Both the low-level API and high-level API are interesting. The main difference is the amount of control you have over the connection and message processing. In the low-level API you have full control over this including being able to override what happens when a client connects, processing of messages, and even disconnection of the client. With the high-level API you for-go this for a much simpler implementation, in this case simpler does not mean less powerful or useful. I think in most cases the high-level API (hubs) will be the right approach and will have plenty of flexibility for what we are trying to accomplish.
In this walk-through I am going to setup a simple application that allows a user action to notify all connected admins. To keep it short and simple this will be done using 2 different pages. Default.aspx will be the client, and Admin.aspx will be the admin page.
To start off we need to create a new web application project (we will use webforms). Once we have a clean project we will use NuGet to install the SignalR package (this actually installs 2 packages, the SignalR.Server package and the SignalR.JS package). Along with the NuGet package we will be using two difference aspx pages; default and admin.
Your project should look something like this.
Our next step is to create our Hub. We will do this in a Services folder within the web project. In this folder we are going to add a new class named “AdminHub”. The contents of this class mirror what you have probably seen already.
The idea here is that by inheriting from the Hub class we are creating an endpoint for a client to subscribe to. This class and the methods within it are callable by JavaScript as will see shortly as well as it calling JavaScript methods on all subscribed clients. The method “SendMessage” could be named anything as it just gets wrapped in a JavaScript factory to allow the clients to call it.
Moving on to the JavaScript we will add the following to our Admin.aspx page:
Looking at the JavaScript the first thing we need is the jQuery reference. In this case it is added in the master page but it could be done here. Next is the reference to SignalR.js. This is used by the prototyped JavaScript and does all the heavy lifting. The next script we add is actually a dynamic proxy generator, because we are using webforms and to be sure we have the right path I am using ResolveClientUrl.
Within our JavaScript we put some code in the jQuery start-up block. The first line created a new proxy to the hub we created previously in c#. It is important to note that naming is very important here as this is all convention based. In this case to utilize our hub “AdminHub” we need a JavaScript proxy named “$.connection.adminHub”. The first letter being lowercase is important. Our next step is to create the callback that our hub will fire. Again this is convention based so the names need to match.
The next two methods we have are wiring up of buttons to fire some c# code. These are the methods we defined on the hub and again this is convention based. Camel Case in c# and lower Camel Case in JS. The last line just initiates the clients persistent connection to the hub.
So now lets say we want to send a message to all the clients of this hub but from another page and without connecting to the hub. Well to do that we just get a reference to the hub we want to message and call the JavaScript method we wish to invoke.
In this case we have a standard asp.net button whose click event is wired up in the code behind. In the click event we get a reference to the clients subscribed to the AdminHub and then invoke the addMessage JavaScript method. That is all it takes to invoke JavaScript for connected clients from your code behind.
All in all, this library is extremely useful in a wide variety of cases and it so simple to integrate with that there is really no reason to not start using it. It is still being actively worked on and is open-source. A working demo is also available at http://www.infinitelooping.com/demos/. Demo source code is available upon request.
Don’t forget to check-out SignalR on github (https://github.com/SignalR/SignalR)








![Image [1]](http://www.infinitelooping.com/blog/wp-content/uploads/2011/05/Image-1-300x207.png)
![Image [2]](http://www.infinitelooping.com/blog/wp-content/uploads/2011/05/Image-2-300x207.png)
![Image [3]](http://www.infinitelooping.com/blog/wp-content/uploads/2011/05/Image-3-300x270.png)
![Image [5]](http://www.infinitelooping.com/blog/wp-content/uploads/2011/05/Image-5-300x200.png)
![Image [6]](http://www.infinitelooping.com/blog/wp-content/uploads/2011/05/Image-6-300x261.png)
![Image [8]](http://www.infinitelooping.com/blog/wp-content/uploads/2011/05/Image-81-300x200.png)
![Image [9]](http://www.infinitelooping.com/blog/wp-content/uploads/2011/05/Image-9-300x168.png)