SignalR

SignalR

 SignalR makes it easy to build multi-user, real-time web applications with ASP.NET. SignalR establishes a persistent bidirectional connection which enables the server to call client methods or send messages to the client. This article gives a brief overview of SignalR. A commented link list helps getting started. This article is also a landing page for SignalR.

(The article isn't a stub any longer, but it still needs some polishing.)

↑ Return to Top


Overview

Concept

SignalR provides a bidirectional communication channel between (web) clients and a server side (web) application. SignalR is not limited to web application. A client  can be every application or web page which uses JavaScript or .NET Framework 4.5 (or 4 with some restrictions) - like Windows Phone apps, SilverLight or Console applications. A SignalR server application has to be build with .NET Framework 4.5 (or 4 with some restrictions).

SignalR's communication channel is

  • Bidirectional
    Client and server can exchange messages or invoke remote methods. I.e. the communication is not limited to the request-response cycle.
  • Persistent
    The connection is established once and used until the application terminates. Persistent connections can reduce the overhead per call significantly.

SignalR supports four communication technologies on the transport layer. Client and Server negotiate the best communication technology – depending on their capabilities – when they establish their connection. SignalR uses the fallback strategy shown in figure 1.


Figure 1: Fallback strategy

SignalR supports these communication technologies:

  • WebSockets
    WebSockets are the best match. WebSockets (and also Server Sent Events) are standardized by the W3C as a part of HTML 5. The .NET Framework supports WebSockets since version 4.5.
  • Server Sent Events
    Server sent events offer a server-to-client push notification using DOM events.
  • Forever Frames
    <<explain>>
  • Long Polling
    <<explain>>.

SignalR has a layered communication architecture on client and server side as shown in figure 2:


Figure 2: Communication Layers

The (internal) Transport Layer handles the different communication technologies. The Persistent Connection API is independent of the underlying technology. It offers a message based API, which allows exchanging data between client and server (and vice versa). The Hub API is the next abstraction level. It enables client and server to invoke remote methods (instead of exchanging mere data).

SignalR exposes two communication levels possible:

  • Persistent Connection API - low level, message-oriented communication
  • Hub API - allows direct call of client and server methods

The Hub API offers the most convenient and preferred communication API. The Persistent Connection API might only be interesting, if you need to integrate with an existing message based server application or if you need for some reason detailed control on the message level.

Practical Scenarios

  • Chat application
  • Multiuser online game
  • Application Monitoring
  • Collaborative Work

Framework

SignalR was first implemented by Damian Edwards and … . It is available as open source.

The SignalR Framework consists of a set of .NET packages and one JavaScript package. The packages are offered via Nuget. Table 1 shows all packages and the (sub) packages they include.

Category Package
Microsoft.AspNet.
Description S
a
m
p
l
e
S
i
g
n
a
l
R
J
s
C
l
i
e
n
t
S
y
s
t
e
m
W
e
b
O
w
i
n
R
e
d
i
s
S
e
r
v
i
c
e
B
u
s
C
o
r
e
Included packages
Sample SignalR.Sample A stock ticker sample x x x   x x     x
Meta Package SignalR Meta package for web apps on IIS & ASP.NET   x x   x x     x
Clients SignalR.Js JavaScript client API     x            
SignalR.Client .NET client API       x          
Host SignalR.SystemWeb Meta package for ASP.NET applications         x x     x
SignalR.Owin OWIN host for SignalR           x     x
Scaleout Buses SignalR.Redis Redis scaleout for SignalR             x   x
SignalR.ServiceBus Service bus scaleout for SignalR               x x
Core SignalR.Core Server side component x

Table 1: SignalR packages

Typical usage scenarios are:

  •  Microsoft.AspNet.SignalR
    is used by Web applications. It's a meta package which contains the most relevant packages for the server side.It also includes the Java Script client API, which is used by the delivered web pages.
  • SignalR.Client
    is used by CLR-based client applications like Windows Phone, WPF or console apps.

 

System Requirements

<<to do>>

Evaluation

Pros

  • bidirectional communication for (web) clients
  • automatically selects the best available communication mechanism
  • it’s not restricted to web clients

Cons

  • Not a reliable communication
    Don’t use it if you need a guaranteed delivery of your messages. Bank Transaction are a negative example.
  • It uses dynamics. Some syntactical errors can only be detected at runtime. However, only a few lines of code are effected. So, it’s not a real problem detected all errors related to the usage of dynamics.

↑ Return to Top


Link Collection

Videos

  • SignalR and WebSockets (6 min)
    Scott Hanselman explains the key concepts of SignalR and WebSockets. An echo application and a stock ticker application are used as demos.
  • Introduction to SignalR - Creating a Cross-Platform game (Screencast on Youtube by Filip Ekberg (MVP), 76 min)
    Starts with an introduction of SignalR and explains how to creates a cross-platform game for different browsers and even Windows 8 Store applications.

Overview Articles

Official SignalR pages

Tutorials, Samples, Demos

Applications Using SignalR

  • Jabbr
    A support forum for SignalR which is implemented  using SignalR. 
  • ShooterR Game
    A multi-user online game with spaceships. You can either play the game or download the source.

Misc

  • Automatic camel casing of properties with SignalR hubs (MSDN Blog, Stuart Leeks, September 2012)
    Stuart writes: "By default, SignalR preserves the case of property names when sending objects from the server to the client. My preference is for PascalCase on the server and camelCase on the client, and in this post I’ll show how you can achieve that."
  • Running SignalR on Mono (TechNet article by Filip Ekberg)
    The article explains the preparation of the SignalR libraries for Mono: compile SignalR dev branch and upload it to the server running Mono and Apache. A small sample application is used to the the installation.

↑ Return to Top


See Also

Leave a Comment
  • Please add 5 and 1 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Carsten Siemens edited Revision 8. Comment: Fixed StatCounter  

  • Carsten Siemens edited Revision 7. Comment: Added tag: has Back to Top link

  • Carsten Siemens edited Revision 6. Comment: Added "See Also" section

  • Carsten Siemens edited Revision 5. Comment: Fixed a larger amount of misspellings

  • Carsten Siemens edited Revision 4. Comment: Removed stub tag. Extended Link Collection.

  • Carsten Siemens edited Revision 3. Comment: Add first content. The article is still a stub.

  • Carsten Siemens edited Revision 2. Comment: Added tag: Carsten Siemens

Page 1 of 1 (7 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Carsten Siemens edited Revision 2. Comment: Added tag: Carsten Siemens

  • Carsten Siemens edited Revision 3. Comment: Add first content. The article is still a stub.

  • Carsten Siemens edited Revision 4. Comment: Removed stub tag. Extended Link Collection.

  • Carsten Siemens edited Revision 5. Comment: Fixed a larger amount of misspellings

  • Carsten Siemens edited Revision 6. Comment: Added "See Also" section

  • Carsten Siemens edited Revision 7. Comment: Added tag: has Back to Top link

  • Carsten Siemens edited Revision 8. Comment: Fixed StatCounter  

Page 1 of 1 (7 items)