SlideShare a Scribd company logo
1 of 30
Building Real Time Applications 
with ASP.NET SignalR 2.0 
Rachel Appel 
Appel Consulting 
http://rachelappel.com 
rachel@rachelappel.com
Agenda 
• Overview of SignalR 
• Configure SignalR and Visual Studio 
• Hubs 
• Connections 
• Deployment
Overview: What is SignlaR? 
• Simplifies real time web development 
• ASP.NET Server and JavaScript Client 
Libraries 
• Real-time persistent connection 
abstraction over HTTP 
• Simplicity 
• Reach 
• Performance 
"Incredibly simply real-time web for .NET" 
– Damian Edwards, SignalR team
Overview: What is SignalR? 
• OWIN http://owin.org/ 
• Katana https://katanaproject.codeplex.com/
Overview: Why Use SignalR? 
• Types of Apps 
• Games, leaderboards 
• Social Applications 
• Business Collaboration 
• Stocks 
• Chat, messaging 
• Dashboards 
• Real time forms 
• Auctions 
• Anything that needs live data
Overview: Where you can use SignalR 
• HTML & ASP.NET apps 
• Windows Store & Phone 
• Any JavaScript client
Overview: SignalR in Action 
http://shootr.signalr.net 
http://JabbR.net
Configure SignalR & Visual Studio 
• http://www.asp.net/signalr 
• NuGet package 
• OWIN References 
• Scripts 
• GitHub download
SignalR Startup 
using Owin; 
using Microsoft.Owin; 
[assembly: OwinStartup(typeof(SR3.Startup))] 
namespace SR3 
{ 
public class Startup 
{ 
public void Configuration(IAppBuilder app) 
{ 
app.MapSignalR(); 
} 
} 
}
DEMO 
• SignalR setup
Overview: SignalR Namespaces 
• Microsoft.AspNet.SignalR.Hub 
• http://msdn.microsoft.com/en-us/library/dn440565(v=vs.118).aspx
Hubs 
• Microsoft.AspNet.SignalR.Hub class 
• Server Side Library 
• Allows for duplex connectivity
Hubs 
• Declare public methods on a hub so that clients can call them. 
• Use the Microsoft.AspNet.SignalR.Hub.Clients property to access all 
clients connected to this hub. 
• Call a function on the client 
• HubName attribute
Hub Events 
public override Task OnConnected() 
{ 
var id = Context.ConnectionId; 
return base.OnConnected(); 
}
Hubs: Transports 
• A full duplex, TCP based protocol 
• Is not HTTP 
• Standardized RFC in 2011
Hubs: Transports 
• Transports 
• WebSockets is the only transport that establishes a true persistent, two-way 
connection between client and server. 
• SSE/Events 
• AJAX Long Polling 
• Forever Frame (IE only) 
• Transport selection process 
• $.connection.hub.logging = true; // to determine transport
From this SO thread 
http://stackoverflow.com/questions/16983630/how-does-signalr-decide-which- 
transport-method-to-be-used 
From this SO user, thomaswr 
http://stackoverflow.com/users/2207506/thomaswr
DEMO 
• Hubs
SignalR Client Script Libraries 
SignalR depends on jQuery 
@Scripts.Render("~/bundles/jquery") 
SignalR script references 
<script src="~/Scripts/jquery.signalR-2.0.2.min.js"></script> 
<script src="~/signalr/hubs"></script>
Connections 
• Client Side 
• PersistentConnection 
• $.connection
Connections: Communications 
• Hub to Connection 
• Connection to Hub 
• Connection to Connection 
• Specific Connections
DEMO 
• Connecting to Hubs
public class ChatHub : Hub 
{ 
public void Send(string name, string message) 
{ 
// send to all 
Clients.All.sendMessage(name, message); 
// send to specific client 
Clients.Client(Context.ConnectionId).sendMessage(message); 
// send only to caller 
Clients.Caller.sendMessage(name, message); 
// send to all but caller 
Clients.Others.sendMessage(name, message); 
// excluding some 
Clients.AllExcept(connectionId1, connectionId2).sendMessage(name, message); 
// send to a group 
Clients.Group(groupName). sendMessage(name, message); 
} 
}
DEMO 
• Connecting to specific Hubs
Send data via QueryString 
• Context.Request 
• Headers 
• QueryString 
// .NET client 
var connection = new HubConnection("http://localhost:8080/", "data=12345"); 
// JavaScript client 
$.connection.hub.qs = "data=12345"; 
// Hub server code 
var qs = Context.Request.QueryString["myInfo"].ToString();
DEMO 
• Using QueryStrings
Connection Status 
• Notify the client of slow or unavailable connectivity 
$.connection.hub.connectionSlow(function () { 
notifyUserOfConnectionProblem(); 
}) 
$.connection.hub.reconnecting(function () { 
notifyUserOfReconnection(); 
});
SignalR Deployment 
• Azure SDK 
• Deployment To-Do's 
• Enable WebSockets 
• Enable V 4.5 
• Multiple Azure instances 
• http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr- 
20/using-signalr-with-windows-azure-web-sites
Thank You! 
Rachel's Website 
http://rachelappel.com 
MSDN Modern Apps Column 
http://msdn.microsoft.com/en-us/ 
magazine/ee532098.aspx?sdmr=RachelAppel&sdmi=authors 
WintellectNOW training videos 
http://bit.ly/RachelNOW

More Related Content

What's hot

Building dynamic applications with the share point client object model
Building dynamic applications with the share point client object modelBuilding dynamic applications with the share point client object model
Building dynamic applications with the share point client object model
Eric Shupps
 
Rich Internet Applications and Flex - 3
Rich Internet Applications and Flex - 3Rich Internet Applications and Flex - 3
Rich Internet Applications and Flex - 3
Vijay Kalangi
 
Microsoft SQL Server 2008
Microsoft SQL Server 2008Microsoft SQL Server 2008
Microsoft SQL Server 2008
Hossein Zahed
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
SharePoint Saturday NY
 
SharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelSharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object Model
Phil Wicklund
 
SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4
Jon Galloway
 

What's hot (20)

Asp.Net Mvc
Asp.Net MvcAsp.Net Mvc
Asp.Net Mvc
 
Sitecore MVC (London User Group, April 29th 2014)
Sitecore MVC (London User Group, April 29th 2014)Sitecore MVC (London User Group, April 29th 2014)
Sitecore MVC (London User Group, April 29th 2014)
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
 
Building dynamic applications with the share point client object model
Building dynamic applications with the share point client object modelBuilding dynamic applications with the share point client object model
Building dynamic applications with the share point client object model
 
Rich Internet Applications and Flex - 3
Rich Internet Applications and Flex - 3Rich Internet Applications and Flex - 3
Rich Internet Applications and Flex - 3
 
ADO.NET Data Services
ADO.NET Data ServicesADO.NET Data Services
ADO.NET Data Services
 
Microsoft SQL Server 2008
Microsoft SQL Server 2008Microsoft SQL Server 2008
Microsoft SQL Server 2008
 
Viper
ViperViper
Viper
 
SharePoint 2013 APIs
SharePoint 2013 APIsSharePoint 2013 APIs
SharePoint 2013 APIs
 
[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
 
Esri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc FinalEsri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc Final
 
SharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object ModelSharePoint 2010 Client-side Object Model
SharePoint 2010 Client-side Object Model
 
SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4
 
Introduction to Asp.net 3.5 using VS 2008
Introduction to Asp.net 3.5 using VS 2008Introduction to Asp.net 3.5 using VS 2008
Introduction to Asp.net 3.5 using VS 2008
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Session 35 - Design Patterns
Session 35 - Design PatternsSession 35 - Design Patterns
Session 35 - Design Patterns
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
 

Viewers also liked

Viewers also liked (12)

SignalR
SignalRSignalR
SignalR
 
SignalR
SignalRSignalR
SignalR
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET Core
 
ASP .NET Core MVC
ASP .NET Core MVCASP .NET Core MVC
ASP .NET Core MVC
 
ASP.NET Core MVC + Web API with Overview (Post RC2)
ASP.NET Core MVC + Web API with Overview (Post RC2)ASP.NET Core MVC + Web API with Overview (Post RC2)
ASP.NET Core MVC + Web API with Overview (Post RC2)
 
ASP.NET Core Unit Testing
ASP.NET Core Unit TestingASP.NET Core Unit Testing
ASP.NET Core Unit Testing
 
SignalR with asp.net
SignalR with asp.netSignalR with asp.net
SignalR with asp.net
 
ASP.NET Core 1.0 Overview: Post-RC2
ASP.NET Core 1.0 Overview: Post-RC2ASP.NET Core 1.0 Overview: Post-RC2
ASP.NET Core 1.0 Overview: Post-RC2
 
ASP.NET Core 1.0 Overview: Pre-RC2
ASP.NET Core 1.0 Overview: Pre-RC2ASP.NET Core 1.0 Overview: Pre-RC2
ASP.NET Core 1.0 Overview: Pre-RC2
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Getting Started with ASP.net Core 1.0
Getting Started with ASP.net Core 1.0Getting Started with ASP.net Core 1.0
Getting Started with ASP.net Core 1.0
 
ASP.NET Core 1.0 Overview
ASP.NET Core 1.0 OverviewASP.NET Core 1.0 Overview
ASP.NET Core 1.0 Overview
 

Similar to Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel

Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)
Deepak Gupta
 
SignalR Dublin ALT.NET
SignalR Dublin ALT.NETSignalR Dublin ALT.NET
SignalR Dublin ALT.NET
Dorin Manoli
 
Native client
Native clientNative client
Native client
zyc901016
 

Similar to Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel (20)

Realtime web experience with signal r
Realtime web experience with signal rRealtime web experience with signal r
Realtime web experience with signal r
 
Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalR
 
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.jsAsynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
 
signalr
signalrsignalr
signalr
 
ASP.NET MVC 5 and SignalR 2
ASP.NET MVC 5 and SignalR 2ASP.NET MVC 5 and SignalR 2
ASP.NET MVC 5 and SignalR 2
 
Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)Real time Communication with Signalr (Android Client)
Real time Communication with Signalr (Android Client)
 
Getting started with ASPNET Core SignalR
Getting started with ASPNET Core SignalRGetting started with ASPNET Core SignalR
Getting started with ASPNET Core SignalR
 
SignalR Dublin ALT.NET
SignalR Dublin ALT.NETSignalR Dublin ALT.NET
SignalR Dublin ALT.NET
 
Real time web apps
Real time web appsReal time web apps
Real time web apps
 
Real Time Data Visualization using asp.net / SignalR + D3.js
Real Time Data Visualization using asp.net / SignalR + D3.jsReal Time Data Visualization using asp.net / SignalR + D3.js
Real Time Data Visualization using asp.net / SignalR + D3.js
 
Signal R 2015
Signal R 2015Signal R 2015
Signal R 2015
 
Xamarin Form using ASP.NET Core SignalR client
Xamarin Form using ASP.NET Core SignalR clientXamarin Form using ASP.NET Core SignalR client
Xamarin Form using ASP.NET Core SignalR client
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
 
Building Real time Application with Azure SignalR Service
Building Real time Application with Azure SignalR ServiceBuilding Real time Application with Azure SignalR Service
Building Real time Application with Azure SignalR Service
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World
Windows 8 Apps and the Outside World
 
Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalR
 
Deep Dive: OpenStack Summit (Red Hat Summit 2014)
Deep Dive: OpenStack Summit (Red Hat Summit 2014)Deep Dive: OpenStack Summit (Red Hat Summit 2014)
Deep Dive: OpenStack Summit (Red Hat Summit 2014)
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
 
Azure signalr service
Azure signalr serviceAzure signalr service
Azure signalr service
 
Native client
Native clientNative client
Native client
 

More from .NET Conf UY

More from .NET Conf UY (17)

Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo FinochiettiRoslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
 
Machine Learning: Inteligencia Artificial no es sólo un tema de Ciencia Ficci...
Machine Learning: Inteligencia Artificial no es sólo un tema de Ciencia Ficci...Machine Learning: Inteligencia Artificial no es sólo un tema de Ciencia Ficci...
Machine Learning: Inteligencia Artificial no es sólo un tema de Ciencia Ficci...
 
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? b...
 
Windows y .NET en la Internet of Things by Pablo Garcia
Windows y .NET en la Internet of Things by Pablo GarciaWindows y .NET en la Internet of Things by Pablo Garcia
Windows y .NET en la Internet of Things by Pablo Garcia
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
 
Metodologías ¿Ágiles o productivas? Una visión desde la trinchera by Marcos E...
Metodologías ¿Ágiles o productivas? Una visión desde la trinchera by Marcos E...Metodologías ¿Ágiles o productivas? Una visión desde la trinchera by Marcos E...
Metodologías ¿Ágiles o productivas? Una visión desde la trinchera by Marcos E...
 
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
 
Emprendiendo un futuro by Gabriel Camargo
Emprendiendo un futuro by Gabriel CamargoEmprendiendo un futuro by Gabriel Camargo
Emprendiendo un futuro by Gabriel Camargo
 
Microsoft Platform Vision by Eduardo Mangarelli
Microsoft Platform Vision by Eduardo MangarelliMicrosoft Platform Vision by Eduardo Mangarelli
Microsoft Platform Vision by Eduardo Mangarelli
 
Arquitectura para Windows Azure: Pienso, luego existo by Fernando Machado
Arquitectura para Windows Azure: Pienso, luego existo by Fernando MachadoArquitectura para Windows Azure: Pienso, luego existo by Fernando Machado
Arquitectura para Windows Azure: Pienso, luego existo by Fernando Machado
 
Extendiendo SharePoint, Project y Office 2013 con el nuevo modelo de Apps by ...
Extendiendo SharePoint, Project y Office 2013 con el nuevo modelo de Apps by ...Extendiendo SharePoint, Project y Office 2013 con el nuevo modelo de Apps by ...
Extendiendo SharePoint, Project y Office 2013 con el nuevo modelo de Apps by ...
 
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald BelchamGetting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
 
Opportunities to Improve System Reliability and Resilience by Donald Belcham
Opportunities to Improve System Reliability and Resilience by Donald BelchamOpportunities to Improve System Reliability and Resilience by Donald Belcham
Opportunities to Improve System Reliability and Resilience by Donald Belcham
 
RESTful Para todos by Diego Sapriza
RESTful Para todos by Diego SaprizaRESTful Para todos by Diego Sapriza
RESTful Para todos by Diego Sapriza
 
Introduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald BelchamIntroduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald Belcham
 
Fun with .NET - Windows Phone, LEGO Mindstorms, and Azure by Dan Fernandez
Fun with .NET - Windows Phone, LEGO Mindstorms, and Azure by Dan FernandezFun with .NET - Windows Phone, LEGO Mindstorms, and Azure by Dan Fernandez
Fun with .NET - Windows Phone, LEGO Mindstorms, and Azure by Dan Fernandez
 
Azure: un parque de diversiones en la nube para el desarrollador moderno by A...
Azure: un parque de diversiones en la nube para el desarrollador moderno by A...Azure: un parque de diversiones en la nube para el desarrollador moderno by A...
Azure: un parque de diversiones en la nube para el desarrollador moderno by A...
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel

  • 1. Building Real Time Applications with ASP.NET SignalR 2.0 Rachel Appel Appel Consulting http://rachelappel.com rachel@rachelappel.com
  • 2. Agenda • Overview of SignalR • Configure SignalR and Visual Studio • Hubs • Connections • Deployment
  • 3. Overview: What is SignlaR? • Simplifies real time web development • ASP.NET Server and JavaScript Client Libraries • Real-time persistent connection abstraction over HTTP • Simplicity • Reach • Performance "Incredibly simply real-time web for .NET" – Damian Edwards, SignalR team
  • 4. Overview: What is SignalR? • OWIN http://owin.org/ • Katana https://katanaproject.codeplex.com/
  • 5. Overview: Why Use SignalR? • Types of Apps • Games, leaderboards • Social Applications • Business Collaboration • Stocks • Chat, messaging • Dashboards • Real time forms • Auctions • Anything that needs live data
  • 6. Overview: Where you can use SignalR • HTML & ASP.NET apps • Windows Store & Phone • Any JavaScript client
  • 7. Overview: SignalR in Action http://shootr.signalr.net http://JabbR.net
  • 8. Configure SignalR & Visual Studio • http://www.asp.net/signalr • NuGet package • OWIN References • Scripts • GitHub download
  • 9. SignalR Startup using Owin; using Microsoft.Owin; [assembly: OwinStartup(typeof(SR3.Startup))] namespace SR3 { public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } }
  • 11. Overview: SignalR Namespaces • Microsoft.AspNet.SignalR.Hub • http://msdn.microsoft.com/en-us/library/dn440565(v=vs.118).aspx
  • 12. Hubs • Microsoft.AspNet.SignalR.Hub class • Server Side Library • Allows for duplex connectivity
  • 13. Hubs • Declare public methods on a hub so that clients can call them. • Use the Microsoft.AspNet.SignalR.Hub.Clients property to access all clients connected to this hub. • Call a function on the client • HubName attribute
  • 14. Hub Events public override Task OnConnected() { var id = Context.ConnectionId; return base.OnConnected(); }
  • 15. Hubs: Transports • A full duplex, TCP based protocol • Is not HTTP • Standardized RFC in 2011
  • 16. Hubs: Transports • Transports • WebSockets is the only transport that establishes a true persistent, two-way connection between client and server. • SSE/Events • AJAX Long Polling • Forever Frame (IE only) • Transport selection process • $.connection.hub.logging = true; // to determine transport
  • 17. From this SO thread http://stackoverflow.com/questions/16983630/how-does-signalr-decide-which- transport-method-to-be-used From this SO user, thomaswr http://stackoverflow.com/users/2207506/thomaswr
  • 19. SignalR Client Script Libraries SignalR depends on jQuery @Scripts.Render("~/bundles/jquery") SignalR script references <script src="~/Scripts/jquery.signalR-2.0.2.min.js"></script> <script src="~/signalr/hubs"></script>
  • 20. Connections • Client Side • PersistentConnection • $.connection
  • 21. Connections: Communications • Hub to Connection • Connection to Hub • Connection to Connection • Specific Connections
  • 23. public class ChatHub : Hub { public void Send(string name, string message) { // send to all Clients.All.sendMessage(name, message); // send to specific client Clients.Client(Context.ConnectionId).sendMessage(message); // send only to caller Clients.Caller.sendMessage(name, message); // send to all but caller Clients.Others.sendMessage(name, message); // excluding some Clients.AllExcept(connectionId1, connectionId2).sendMessage(name, message); // send to a group Clients.Group(groupName). sendMessage(name, message); } }
  • 24. DEMO • Connecting to specific Hubs
  • 25. Send data via QueryString • Context.Request • Headers • QueryString // .NET client var connection = new HubConnection("http://localhost:8080/", "data=12345"); // JavaScript client $.connection.hub.qs = "data=12345"; // Hub server code var qs = Context.Request.QueryString["myInfo"].ToString();
  • 26. DEMO • Using QueryStrings
  • 27. Connection Status • Notify the client of slow or unavailable connectivity $.connection.hub.connectionSlow(function () { notifyUserOfConnectionProblem(); }) $.connection.hub.reconnecting(function () { notifyUserOfReconnection(); });
  • 28. SignalR Deployment • Azure SDK • Deployment To-Do's • Enable WebSockets • Enable V 4.5 • Multiple Azure instances • http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr- 20/using-signalr-with-windows-azure-web-sites
  • 29.
  • 30. Thank You! Rachel's Website http://rachelappel.com MSDN Modern Apps Column http://msdn.microsoft.com/en-us/ magazine/ee532098.aspx?sdmr=RachelAppel&sdmi=authors WintellectNOW training videos http://bit.ly/RachelNOW

Editor's Notes

  1. Long polling is itself not a true push; long polling is a variation of the traditional polling technique, but it allows emulating a push mechanism under circumstances where a real push is not possible, such as sites with security policies that require rejection of incoming HTTP/S Requests. With long polling, the client requests information from the server exactly as in normal polling, except it issues its HTTP/S requests (polls) at a much slower frequency. If the server does not have any information available for the client when the poll is received, instead of sending an empty response, the server holds the request open and waits for response information to become available. Once it does, the server immediately sends an HTTP/S response to the client, completing the open HTTP/S Request. In this way the usual response latency (the time between when the information first becomes available and the next client request) otherwise associated with polling clients is eliminated. For example, BOSH is a popular, long-lived HTTP technique used as a long-polling alternative to TCP when TCP is difficult or impossible to employ directly (e.g., in a web browser);[9] it is also an underlying technology in the XMPP, which Apple uses for its iCloud push support.
  2. Each SignalR app is an OWIN app (open web interface for .net). http://owin.org
  3. Every OWIN Application has a startup class where you specify components for the application pipeline. There are different ways you can connect your startup class with the runtime, depending on the hosting model you choose (OwinHost, IIS, and IIS-Express). The startup class shown in this tutorial can be used in every hosting application. You connect the startup class with the hosting runtime using one of the these approaches: Naming Convention: Katana looks for a class named Startup in namespace matching the assembly name or the global namespace. OwinStartup Attribute: This is the approach most developers will take to specify the startup class. The following attribute will set the startup class to the TestStartup class in the StartupDemo namespace.[assembly: OwinStartup(typeof(StartupDemo.TestStartup))]The OwinStartup attribute overrides the naming convention. You can also specify a friendly name with this attribute, however, using a friendly name requires you to also use the appSetting element in the configuration file.
  4. Use NuGet to install SignalR references IN the startup, the code maps SignalR hubs to the app builder pipeline at "/signalr".
  5. $.connection.hub.logging = true; // to verify the transport (websockets or a fallback like comet or forever frame connection.start({ transport: 'longPolling' });You can specify a fallback order if you want a client to try specific transports in order. The following code snippet demonstrates trying WebSocket, and failing that, going directly to Long Polling. connection.start({ transport: ['webSockets','longPolling'] });
  6. A Hub is a more high-level pipeline built upon the Connection API that allows your client and server to call methods on each other directly When server-side code calls a method on the client, a packet is sent across the active transport that contains the name and parameters of the method to be called (when an object is sent as a method parameter, it is serialized using JSON). The client then matches the method name to methods defined in client-side code. If there is a match, the client method will be executed using the deserialized parameter data. The method call can be monitored using tools like Fiddler. The following image shows a method call sent from a SignalR server to a web browser client in the Logs pane of Fiddler. 
  7. http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-javascript-client Note: In JavaScript the reference to the server class and its members is in camel case. The code sample references the C# ChatHub class in JavaScript as chatHub
  8. From WikiPedia: WebSocket is a protocol providing full-duplex communications channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455in 2011, and the WebSocket API in Web IDL is being standardized by the W3C. WebSocket is designed to be implemented in web browsers and web servers, but it can be used by any client or server application. The WebSocket Protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request.[1] The WebSocket protocol makes possible more interaction between a browser and a web site, facilitating live content and the creation of real-time games.  A full-duplex (FDX) system, or sometimes called double-duplex, allows communication in both directions, and, unlike half-duplex, allows this to happen simultaneously. Land-line telephone networks are full-duplex, since they allow both callers to speak and be heard at the same time. HTTP is a half duplex system, meaning that it has two way communication but only one way at a time. Like a single elevator in a small building.
  9. Transport selection process The following list shows the steps that SignalR uses to decide which transport to use. If the browser is Internet Explorer 8 or earlier, Long Polling is used. If JSONP is configured (that is, the jsonp parameter is set to true when the connection is started), Long Polling is used. If a cross-domain connection is being made (that is, if the SignalR endpoint is not in the same domain as the hosting page), then WebSocket will be used if the following criteria are met: The client supports CORS (Cross-Origin Resource Sharing). For details on which clients support CORS, see CORS at caniuse.com. The client supports WebSocket The server supports WebSocket If any of these criteria are not met, Long Polling will be used. For more information on cross-domain connections, see How to establish a cross-domain connection. If JSONP is not configured and the connection is not cross-domain, WebSocket will be used if both the client and server support it. If either the client or server do not support WebSocket, Server Sent Events is used if it is available. If Server Sent Events is not available, Forever Frame is attempted. If Forever Frame fails, Long Polling is used. You can determine what transport your application is using by enabling logging on your hub, and opening the console window in your browser. To enable logging for your hub's events in a browser, add the following command to your client application: $.connection.hub.logging = true;
  10. A Connection represents a simple endpoint for sending single-recipient, grouped, or broadcast messages When OnConnected, OnDisconnected, and OnReconnected are called Each time a browser navigates to a new page, a new connection has to be established, which means SignalR will execute the OnDisconnected method followed by the OnConnected method. SignalR always creates a new connection ID when a new connection is established. The OnReconnected method is called when there has been a temporary break in connectivity that SignalR can automatically recover from, such as when a cable is temporarily disconnected and reconnected before the connection times out. The OnDisconnected method is called when the client is disconnected and SignalR can't automatically reconnect, such as when a browser navigates to a new page. Therefore, a possible sequence of events for a given client is OnConnected, OnReconnected, OnDisconnected; or OnConnected,OnDisconnected. You won't see the sequence OnConnected, OnDisconnected, OnReconnected for a given connection. The OnDisconnected method doesn't get called in some scenarios, such as when a server goes down or the App Domain gets recycled. When another server comes on line or the App Domain completes its recycle, some clients may be able to reconnect and fire the OnReconnected event. For more information, see Understanding and Handling Connection Lifetime Events in SignalR. $.connection.hub.logging = true; // to verify the transport (websockets or a fallback like comet or forever frame connection.start({ transport: 'longPolling' });You can specify a fallback order if you want a client to try specific transports in order. The following code snippet demonstrates trying WebSocket, and failing that, going directly to Long Polling. connection.start({ transport: ['webSockets','longPolling'] });
  11. var connection = new HubConnection("http://localhost:8080/", "myInfo=12345"); // .NET client $.connection.hub.qs = "myInfo=12345"; // the js client Context.Request.QueryString["myInfo"].ToString(); // in hub code on server
  12. How to notify the user about disconnections In some applications you might want to display a message to the user when there are connectivity problems. You have several options for how and when to do this. The following code samples are for a JavaScript client using the generated proxy. Handle the connectionSlow event to display a message as soon as SignalR is aware of connection problems, before it goes into reconnecting mode. $.connection.hub.connectionSlow(function() { notifyUserOfConnectionProblem(); // Your function to notify user. }); Handle the reconnecting event to display a message when SignalR is aware of a disconnection and is going into reconnecting mode. $.connection.hub.reconnecting(function() { notifyUserOfTryingToReconnect(); // Your function to notify user. });
  13. You can use the Windows Azure Service Bus Backplane for multiple instances of Azure http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/using-signalr-with-windows-azure-web-sites