This is a very simple example of how we can use SignalR, based on the Microsoft Virtual Academy course "Building apps with ASP.NET 4.5". It can be used as a guide for building a more complex web app. This solution requires NuGet packages to be downloaded. Visual Studio will download the necessary packages automatically. This solution is designed for Visual Studio 2012
This application displays a div shape that the users can drag. The position of the shape in all other browsers will then be updated to match the position of the dragged shape.
As the server component, this web page contains a C# implementation of the SignalR Hub class. As the client component, it has an HTML page using JQuery .
These concepts are associated with applications in real-time gaming and other simulation applications.

Index.html
01.<!DOCTYPE html>02.<htmlxmlns="http://www.w3.org/1999/xhtml">03.<head>04.<title>SignalR Example</title>05.06.#shape {07.width: 100px;08.height: 100px;09.background-color: red;10.cursor:move;11.}12.13.#count {14.font-size:60px;15.12.13.#count {14.&black;">color:lightGray;16.float:right;17.}18.19.</head>20.<body>21.22.<divid="count">0</div>23.<divid="shape"></div>24.25.<scriptsrc="Scripts/jquery-1.6.4.js"></script>26.<scriptsrc="Scripts/jquery-ui-1.10.3.js"></script>27.<scriptsrc="Scripts/jquery.signalR-1.1.3.js"></script>28.<scriptsrc="/signalr/hubs"></script> <!--this is for automatically29.generate a javascript proxy class for our server class-->30.<script>31.32.$(function () {33.34.var hub = $.connection.moveShape, //set hub with the server side class35.$shape = $("#shape");36.37.38.39.hub.client.usersConnected = function (numUsers) { //this instanciate the40.usersConnected function receiving the numUsers parameter which is the number of users connected41.$("#count").text(numUsers); //show the number of users connected inside a div42.};43.44.45.46.47.hub.client.shapeMoved = function (x, y) { //this instanciate the shapeMoved function48.receiving x, y49.$shape.css({ left: x, top: y }); //this moves the shape in the clients to50.the coords x, y51.};52.53.$.connection.hub.start().done(function () {//when the connection is ready,54.we going to make the shape draggable55.$shape.draggable({56.drag: function () { //when the user drag the shape, we going to57.send to the server the x, y values58.hub.server.moveShape(this.offsetLeft, this.offsetTop || 0);59.}60.});61.});62.});63.64.</script>65.</62.});63.64.</scriight:bold;">body>66.</html>
MoveShapeHub.cs
01.usingMicrosoft.AspNet.SignalR;02.usingMicrosoft.AspNet.SignalR.Hubs;03.usingSystem;04.usingSystem.Collections.Generic;05.usingSystem.Linq;06.usingSystem.Threading.Tasks;07.usingSystem.Web;08.09.namespaceSignalR.MoveShape10.{11.12.publicstaticclassUserHandler//this static class is to store the number of13.users conected at the same time14.{15.publicstaticHashSet<string> ConnectedIds =newHashSet<string>();16.}17.18.[HubName("moveShape")]//this is for use a name to use in the client19.publicclassMoveShapeHub : Hub20.{21.publicvoidmoveShape(intx,inty)// this method will be called from22.the client, when the user drag/move the shape23.{24.25.Clients.Others.shapeMoved(x, y);// this method will send the coord x, y26.to the other users but the user draging the shape27.28.}29.30.publicolor:dimgray;padding-right:0.3em;display:block;float:left;">27.28.}29.30.Task OnConnected()//override OnConnect, OnReconnected and OnDisconnected31.to knowifa userisconnected or disconnected32.{33.UserHandler.ConnectedIds.Add(Context.ConnectionId);//add a connection id to the list34.Clients.All.usersConnected(UserHandler.ConnectedIds.Count());//this will send to ALL the clients35.the number of users connected36.returnbase.OnConnected();37.}38.39.publicoverrideTask OnReconnected()40.{41.UserHandler.ConnectedIds.Add(Context.ConnectionId);42.Clients.All.usersConnected(UserHandler.ConnectedIds.Count());43.returnbase.OnConnected();44.}45.46.publicoverrideTask OnDisconnected()47.{48.UserHand46.publicoverrideTask OnDisconnected()47.{49.Clients.All.usersConnected(UserHandler.ConnectedIds.Count());50.returnbase.OnDisconnected();51.}52.53.54.55.}56.}
Globa.asax.cs
01.usingSystem;02.usingSystem.Collections.Generic;03.usingSystem.Linq;04.usingSystem.Web;05.usingSystem.Web.Routing;06.usingSystem.Web.Security;07.usingSystem.Web.SessionState;08.09.namespaceSignalR10.{11.publicclassGlobal : System.Web.HttpApplication12.{13.14.publicvoidApplication_Start()15.{16.// Register the default hubs route: ~/signalr17.RouteTable.Routes.MapHubs();18.}19.20.protectedvoidSession_Start(objectsender, EventArgs e)21.{22.23.}24.25.protectedvoidApplication_BeginRequest(objectsender, EventArgs e)26.{27.28.}29.30.protectedvoidApplication_AuthenticateRequest(objectsender, EventArgs e)31.{32.33.}34.35.protectedvoidApplication_Error(objectsender, EventArgs e)36.{37.38.}39.40.protectedvoidSession_End(objectsender, EventArgs e)41.{42.43.}44.45.protectedvoidApplication_End(objectsender, EventArgs e)46.{47.48.}49.}50.}