SignalR Slideshow

SignalR

Pushing realtime data to the client


Phil Denoncourt

www.philknows.net
phil@denoncourtassociates.com

SignalR Overview

SignalR is...

  • Library which abtracts communications from ASP.NET server directly to clients
  • Uses a variety of methods depending on
    • Network conditions/firewall
    • Browser capability
  • Methods are:
    • HTML 5 WebSockets
    • Server Sent Events
    • Forever Frame
    • Ajax Long Polling
  • Allows you to send async messages from server to client, or client to server

History SignalR Project

  • Created July, 2011 by David Fowler as moonlighting project
  • Found that Damian Edward was working on a similiar project
    • So they merged their code and combined effort
  • MIT Licensed, hosted on GitHub

Supported Clients

  • Browsers
    • IE 8+, Chrome, Safari, Firefox, Opera
    • Mobile: Android, iOS, Windows Mobile
  • Desktop
    • .NET (winForm, WPF, Silverlight, Mono)
    • iOS Native Apps (3rd party)
    • Android Native Apps (3rd party)
    • Anything that runs Javascript

Server Requirements

  • Operating System
    • Windows Server 2012, 2008r2
    • Windows 8, 7
    • Windows Azure
  • Server components written for .NET 4.5
  • Generally hosted in web app
    • Websockets rely on IIS 8.0
  • Can also be self hosted in windows service or console app.

Modes of development

  • Persistent Connections
    • Low level API for sending bits to client
    • Broadcasts an object directly to a set of clients
    • Client is responsible for routing the message within the page
    • Generally won't use this method.
  • Hubs
    • Main abstraction used in SignalR
    • Represents a set of clients connected to the same "channel"
    • Through the javascript library, messages will be routed to functions on the hub.

Application examples

Shared educational experiences

  • As I move, you move
  • One presenter
    • Transmits messages to everyone connected to hub

Realtime Dashboards

  • Server pushes data to clients as soon as it is changed
  • Some sort of watcher on the server
  • As soon as data changes, broadcast to all clients
  • Broadcast deltas, or entire set of data
  • Clients need an initial set of data when page is loaded

Long running transaction

  • Allows you to provide realtime feedback to customer
  • Need to send in a connection id, or group name to your transaction processor
  • SignalR will reconnect if network connection drops
  • Good way to instill confidence in your system

Collaborative Applications

  • Allows many people to work on documents together
    • And see the outcome together
  • Clients need to download an initial set of data.
  • Should be handling reconnection event.
  • Need to make provisions for concurrency.

Other concerns

Scaling

  • A single server can handle 1000's of connections
  • Scales out to multiple servers using a shared backend
  • Out of the box providers include
    • SQL Server
    • Redis
    • Azure service bus
  • Extensible so that you can create your own provider
  • Bound by allowable connections to IIS

Security

  • Uses ASP.NET security providers
  • By default won't work cross-domain
    • Enable using CORS library.

Extensibility

  • Specific points of extensibility
    • Message bus transport
    • Assembly locator to search for hubs within
    • Javascript proxy generator
    • Javascript proxy minifier
    • JSON serializer

All in all

    • SignalR is a very useful library to allow bidirectional communication between client and server
    • Supports many different devices.
    • Bidirection communication is harder than poll.