SlideShare a Scribd company logo
SignalR
Simplest way to achieve real-time web functionality
Agenda
• Introduction
• Hubs
• Scale Out / Backplane
• Self Host
Intro to SignalR
• A library for real-time web functionality
• Built on OWIN(SignalR 2.x)
• Open Web Interface for .Net
• Open source on Github
Intro to SignalR
• Built on persistent connections
• Remote Procedure Call(RPC)
• Server push
• Transports
• Web Socket
• Server Sent Event
• Forever Frame
• Long Polling
• Fallback
Transports
comet HTML 5
Long Polling Forever Frame
Server Sent
Event
Web Socket
Long Polling
• Response when server data
changed
Forever Frame
• Hidden iframe
• Only for IE
Server Sent Event
• HTML5 EventSource
• One way communication
(Server to client)
• Except IE
Web Socket
• Persistent full-duplex
bi-directional connection
• Criteria are met for both
server and client side
Web Browser Transport Requirements
Transport
Internet
Explorer
Chrome
(Windows or
iOS)
Firefox
Safari
(OSX or iOS)
Android
WebSockets 10+ current - 1 current - 1 current – 1 N/A
Server-Sent
Events
N/A current - 1 current - 1 current - 1 N/A
ForeverFrame 8+ N/A N/A N/A 4.1
Long Polling 8+ current – 1 current - 1 current - 1 4.1
Core Architecture
• pub/sub
• Publish-Subscribe pattern
Core Architecture
publisher
message cache
worker worker worker
client client client client client
message bus
1.Message serialized,
saved to cache
associated with signal,
topic is marked for
delivery, publish call
returns
2. Worker is scheduled for
a signal, selects a waiting
subscriber, retrieves
message from cache
3. Worker sends message
to client as bytes over a
transport
Watch out
• Sending large messages
• Memory leaks – all hub instances are transient
• Session – don’t use it from SignalR, at all, ever (no support)
Platform Support
• OS
• Windows 2008 r2 to 2012
• Windows 7+
• Windows Azure(No support Web Socket)
• .Net framework
• .Net 4.5+(Web Socket support)
• .Net 4
• IIS
• IIS 8(Web Socket support)
• IIS 7 and IIS 7.5
Hubs
• Least developer work
• Monitor network transport
• Specifying network technology
• Accept/Return simple type, complex type
• Complex objects serialized to/from JSON
Hubs-Server side
• Register in Startup.cs
• HubName attribute
• Broadcast
• Clients.All.dynamic
• Clients.Caller.dynamic
• Clients.Others.dynamic
• Clients.Caller(Context.ConnectionId).dynamic
• Clients.AllExcept(connectionId, connectionId).dynamic
• Clients.User(userId).dynamic
PM> Install-Package Microsoft.AspNet.SignalR
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
[HubName("alias")]
public class NewHub : Hub
{
}
Hubs-Client side
• jQuery base
• $.connection.hubName -> Camelcase
• $.connection.hub.start()
• $.connection.hub.start({ transport: [‘webSockets’,
‘longPolling’] })
• $.connection.hub.logging = true -> Debugging
• hub.server.serverMethod
• hub.client.dynamicMethod
<script src="~/scripts/jquery-
1.6.4.min.js"></script>
<script src="~/scripts/jquery.signalR-
2.2.0.js"></script>
<script src="~/SignalR/hubs"></script>
PM> Install-Package Microsoft.AspNet.SignalR.JS
Hubs
• Server
• OnConnected
• OnReconnected
• OnDisconnected
• Client
• $.connection.hub.start
• $.connection.hub.reconnecting
• $.connection.hub.disconnected
• $.connection.hub.connectionSlow
DEMO: First SignalR
Hubs
• Groups
• Send message to particular groups
• Not persisted on server
• Server side
• Groups.Add(Context.ConnectionId, groupName)
• Groups.Remove(Context.ConnectionId, groupName)
• Broadcast
• Clients.Group(groupName).dynamic
• Clients.Group(groupName, connectionId,
connectionId).dynamic
• Clients.OthersInGroup(groupName).dynamic
DEMO: UKWL with SignalR
Scale out
• Problem
client
Server 1 Server 2
Scale out + Backplane
Backplane
clien
t
Server
clien
t
clien
t
clien
t
clien
t
clien
t
Server
clien
t
clien
t
clien
t
clien
t
clien
t
Server
clien
t
clien
t
clien
t
clien
t
Backplane
• HOW TO
• Nuget + ONE line code
• Limitation
• Much slower than single server
• Lower rate
Load patterns
• Server broadcast – low rate, message to all clients
• Server push – low rate, message to unique clients
• User event driven – broadcast on client action
• High frequency – fixed high rate, unique messages
Backplane
• Redis
• SQL Server
• Azure Service Bus
PM> Install-Package Microsoft.AspNet.SignalR.Redis
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
GlobalHost.DependencyResolver.UseRedis("server", port, "password",
"AppName");
DEMO: Scale out with Redis
Self host
• Normally hosted in IIS
• WHY self-hosted
• No IIS
• Performance issue
• Console / Windows Form Application
Self host - Server
class Program
{
static void Main(string[] args)
{
using (WebApp.Start("http://localhost:8080")) {
Console.ReadLine();
}
}
}
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
PM> Install-Package Microsoft.AspNet.SignalR.SelfHost
PM> Install-Package Microsoft.Owin.Cors
Self host - Client
<script type="text/javascript">
$(function () {
$.connection.hub.url = "http://localhost:8080/signalr";
});
</script>
PM> Install-Package Microsoft.AspNet.SignalR.JS
<script src="~/scripts/jquery-1.6.4.min.js"></script>
<script src="~/scripts/jquery.signalR-2.2.0.js"></script>
<script src="http://localhost:8080/signalr/hubs"></script>
Q & A

More Related Content

What's hot

Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalR
University of Hawai‘i at Mānoa
 
Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalR
Adam Mokan
 
Real time web with SignalR
Real time web with SignalRReal time web with SignalR
Real time web with SignalR
Alessandro Melchiori
 
Intro to signalR
Intro to signalRIntro to signalR
Intro to signalR
Mindfire Solutions
 
Building Realtime Web Applications With ASP.NET SignalR
Building Realtime Web Applications With ASP.NET SignalRBuilding Realtime Web Applications With ASP.NET SignalR
Building Realtime Web Applications With ASP.NET SignalRShravan Kumar Kasagoni
 
SignalR with ASP.NET MVC 6
SignalR with ASP.NET MVC 6SignalR with ASP.NET MVC 6
SignalR with ASP.NET MVC 6
Tung Nguyen Thanh
 
«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET
Alessandro Giorgetti
 
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
SignalRSignalR
SignalR
Eyal Vardi
 
SignalR. Code, not toothpaste - TechDays Belgium 2012
SignalR. Code, not toothpaste - TechDays Belgium 2012SignalR. Code, not toothpaste - TechDays Belgium 2012
SignalR. Code, not toothpaste - TechDays Belgium 2012Maarten Balliauw
 
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
Kevin Griffin
 
Real-time Communications with SignalR
Real-time Communications with SignalRReal-time Communications with SignalR
Real-time Communications with SignalR
Shravan Kumar Kasagoni
 
Microsoft signal r
Microsoft signal rMicrosoft signal r
Microsoft signal rrustd
 
Signalr with ASP.Net part2
Signalr with ASP.Net part2Signalr with ASP.Net part2
Signalr with ASP.Net part2
Esraa Ammar
 
Real time websites and mobile apps with SignalR
Real time websites and mobile apps with SignalRReal time websites and mobile apps with SignalR
Real time websites and mobile apps with SignalR
Roy Cornelissen
 
Web Real-time Communications
Web Real-time CommunicationsWeb Real-time Communications
Web Real-time Communications
Alexei Skachykhin
 
Real time web applications with SignalR (BNE .NET UG)
Real time web applications with SignalR (BNE .NET UG)Real time web applications with SignalR (BNE .NET UG)
Real time web applications with SignalR (BNE .NET UG)
brendankowitz
 
Eclipse Kapua messaging refactoring proposal
Eclipse Kapua messaging refactoring proposalEclipse Kapua messaging refactoring proposal
Eclipse Kapua messaging refactoring proposal
Henryk Konsek
 
Signal R 2015
Signal R 2015Signal R 2015
Signal R 2015
Mihai Coscodan
 
Api gateway in microservices
Api gateway in microservicesApi gateway in microservices
Api gateway in microservices
Kunal Hire
 

What's hot (20)

Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalR
 
Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalR
 
Real time web with SignalR
Real time web with SignalRReal time web with SignalR
Real time web with SignalR
 
Intro to signalR
Intro to signalRIntro to signalR
Intro to signalR
 
Building Realtime Web Applications With ASP.NET SignalR
Building Realtime Web Applications With ASP.NET SignalRBuilding Realtime Web Applications With ASP.NET SignalR
Building Realtime Web Applications With ASP.NET SignalR
 
SignalR with ASP.NET MVC 6
SignalR with ASP.NET MVC 6SignalR with ASP.NET MVC 6
SignalR with ASP.NET MVC 6
 
«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET
 
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)
 
SignalR
SignalRSignalR
SignalR
 
SignalR. Code, not toothpaste - TechDays Belgium 2012
SignalR. Code, not toothpaste - TechDays Belgium 2012SignalR. Code, not toothpaste - TechDays Belgium 2012
SignalR. Code, not toothpaste - TechDays Belgium 2012
 
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
 
Real-time Communications with SignalR
Real-time Communications with SignalRReal-time Communications with SignalR
Real-time Communications with SignalR
 
Microsoft signal r
Microsoft signal rMicrosoft signal r
Microsoft signal r
 
Signalr with ASP.Net part2
Signalr with ASP.Net part2Signalr with ASP.Net part2
Signalr with ASP.Net part2
 
Real time websites and mobile apps with SignalR
Real time websites and mobile apps with SignalRReal time websites and mobile apps with SignalR
Real time websites and mobile apps with SignalR
 
Web Real-time Communications
Web Real-time CommunicationsWeb Real-time Communications
Web Real-time Communications
 
Real time web applications with SignalR (BNE .NET UG)
Real time web applications with SignalR (BNE .NET UG)Real time web applications with SignalR (BNE .NET UG)
Real time web applications with SignalR (BNE .NET UG)
 
Eclipse Kapua messaging refactoring proposal
Eclipse Kapua messaging refactoring proposalEclipse Kapua messaging refactoring proposal
Eclipse Kapua messaging refactoring proposal
 
Signal R 2015
Signal R 2015Signal R 2015
Signal R 2015
 
Api gateway in microservices
Api gateway in microservicesApi gateway in microservices
Api gateway in microservices
 

Similar to signalr

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
Stuart (Pid) Williams
 
SignalR: Add real-time to your applications
SignalR: Add real-time to your applicationsSignalR: Add real-time to your applications
SignalR: Add real-time to your applicationsEugene Zharkov
 
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
Jaliya Udagedara
 
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel AppelBuilding Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
.NET Conf UY
 
Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with FayeMatjaž Lipuš
 
Realtime web experience with signal r
Realtime web experience with signal rRealtime web experience with signal r
Realtime web experience with signal r
Ran Wahle
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
Prabhakaran Soundarapandian
 
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
NGINX, Inc.
 
Node.js to the rescue
Node.js to the rescueNode.js to the rescue
Node.js to the rescue
Marko Heijnen
 
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
Christian Heindel
 
AWS as platform for scalable applications
AWS as platform for scalable applicationsAWS as platform for scalable applications
AWS as platform for scalable applications
Roman Gomolko
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
C2B2 Consulting
 
XMPP/Jingle(VoIP)/Perl Ocean 2012/03
XMPP/Jingle(VoIP)/Perl Ocean 2012/03XMPP/Jingle(VoIP)/Perl Ocean 2012/03
XMPP/Jingle(VoIP)/Perl Ocean 2012/03
Lyo Kato
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax Push
Doris Chen
 
AMF Flash and .NET
AMF Flash and .NETAMF Flash and .NET
AMF Flash and .NETYaniv Uriel
 
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
Sencha
 
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
Sencha
 
Web services - A Practical Approach
Web services - A Practical ApproachWeb services - A Practical Approach
Web services - A Practical Approach
Madhaiyan Muthu
 
Codestrong 2012 breakout session building your own custom cloud services
Codestrong 2012 breakout session   building your own custom cloud servicesCodestrong 2012 breakout session   building your own custom cloud services
Codestrong 2012 breakout session building your own custom cloud servicesAxway Appcelerator
 
Overview of SignalR
Overview of SignalROverview of SignalR
Overview of SignalR
Amit Naik
 

Similar to signalr (20)

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
 
SignalR: Add real-time to your applications
SignalR: Add real-time to your applicationsSignalR: Add real-time to your applications
SignalR: Add real-time to your applications
 
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
 
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel AppelBuilding Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
 
Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with Faye
 
Realtime web experience with signal r
Realtime web experience with signal rRealtime web experience with signal r
Realtime web experience with signal r
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
 
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
 
Node.js to the rescue
Node.js to the rescueNode.js to the rescue
Node.js to the rescue
 
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
 
AWS as platform for scalable applications
AWS as platform for scalable applicationsAWS as platform for scalable applications
AWS as platform for scalable applications
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
 
XMPP/Jingle(VoIP)/Perl Ocean 2012/03
XMPP/Jingle(VoIP)/Perl Ocean 2012/03XMPP/Jingle(VoIP)/Perl Ocean 2012/03
XMPP/Jingle(VoIP)/Perl Ocean 2012/03
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax Push
 
AMF Flash and .NET
AMF Flash and .NETAMF Flash and .NET
AMF Flash and .NET
 
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
 
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
 
Web services - A Practical Approach
Web services - A Practical ApproachWeb services - A Practical Approach
Web services - A Practical Approach
 
Codestrong 2012 breakout session building your own custom cloud services
Codestrong 2012 breakout session   building your own custom cloud servicesCodestrong 2012 breakout session   building your own custom cloud services
Codestrong 2012 breakout session building your own custom cloud services
 
Overview of SignalR
Overview of SignalROverview of SignalR
Overview of SignalR
 

signalr

  • 1. SignalR Simplest way to achieve real-time web functionality
  • 2. Agenda • Introduction • Hubs • Scale Out / Backplane • Self Host
  • 3. Intro to SignalR • A library for real-time web functionality • Built on OWIN(SignalR 2.x) • Open Web Interface for .Net • Open source on Github
  • 4. Intro to SignalR • Built on persistent connections • Remote Procedure Call(RPC) • Server push • Transports • Web Socket • Server Sent Event • Forever Frame • Long Polling • Fallback
  • 5. Transports comet HTML 5 Long Polling Forever Frame Server Sent Event Web Socket
  • 6. Long Polling • Response when server data changed
  • 7. Forever Frame • Hidden iframe • Only for IE
  • 8. Server Sent Event • HTML5 EventSource • One way communication (Server to client) • Except IE
  • 9. Web Socket • Persistent full-duplex bi-directional connection • Criteria are met for both server and client side
  • 10. Web Browser Transport Requirements Transport Internet Explorer Chrome (Windows or iOS) Firefox Safari (OSX or iOS) Android WebSockets 10+ current - 1 current - 1 current – 1 N/A Server-Sent Events N/A current - 1 current - 1 current - 1 N/A ForeverFrame 8+ N/A N/A N/A 4.1 Long Polling 8+ current – 1 current - 1 current - 1 4.1
  • 11. Core Architecture • pub/sub • Publish-Subscribe pattern
  • 12. Core Architecture publisher message cache worker worker worker client client client client client message bus 1.Message serialized, saved to cache associated with signal, topic is marked for delivery, publish call returns 2. Worker is scheduled for a signal, selects a waiting subscriber, retrieves message from cache 3. Worker sends message to client as bytes over a transport
  • 13. Watch out • Sending large messages • Memory leaks – all hub instances are transient • Session – don’t use it from SignalR, at all, ever (no support)
  • 14. Platform Support • OS • Windows 2008 r2 to 2012 • Windows 7+ • Windows Azure(No support Web Socket) • .Net framework • .Net 4.5+(Web Socket support) • .Net 4 • IIS • IIS 8(Web Socket support) • IIS 7 and IIS 7.5
  • 15. Hubs • Least developer work • Monitor network transport • Specifying network technology • Accept/Return simple type, complex type • Complex objects serialized to/from JSON
  • 16. Hubs-Server side • Register in Startup.cs • HubName attribute • Broadcast • Clients.All.dynamic • Clients.Caller.dynamic • Clients.Others.dynamic • Clients.Caller(Context.ConnectionId).dynamic • Clients.AllExcept(connectionId, connectionId).dynamic • Clients.User(userId).dynamic PM> Install-Package Microsoft.AspNet.SignalR public partial class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } [HubName("alias")] public class NewHub : Hub { }
  • 17. Hubs-Client side • jQuery base • $.connection.hubName -> Camelcase • $.connection.hub.start() • $.connection.hub.start({ transport: [‘webSockets’, ‘longPolling’] }) • $.connection.hub.logging = true -> Debugging • hub.server.serverMethod • hub.client.dynamicMethod <script src="~/scripts/jquery- 1.6.4.min.js"></script> <script src="~/scripts/jquery.signalR- 2.2.0.js"></script> <script src="~/SignalR/hubs"></script> PM> Install-Package Microsoft.AspNet.SignalR.JS
  • 18. Hubs • Server • OnConnected • OnReconnected • OnDisconnected • Client • $.connection.hub.start • $.connection.hub.reconnecting • $.connection.hub.disconnected • $.connection.hub.connectionSlow
  • 20. Hubs • Groups • Send message to particular groups • Not persisted on server • Server side • Groups.Add(Context.ConnectionId, groupName) • Groups.Remove(Context.ConnectionId, groupName) • Broadcast • Clients.Group(groupName).dynamic • Clients.Group(groupName, connectionId, connectionId).dynamic • Clients.OthersInGroup(groupName).dynamic
  • 21. DEMO: UKWL with SignalR
  • 23. Scale out + Backplane Backplane clien t Server clien t clien t clien t clien t clien t Server clien t clien t clien t clien t clien t Server clien t clien t clien t clien t
  • 24. Backplane • HOW TO • Nuget + ONE line code • Limitation • Much slower than single server • Lower rate
  • 25. Load patterns • Server broadcast – low rate, message to all clients • Server push – low rate, message to unique clients • User event driven – broadcast on client action • High frequency – fixed high rate, unique messages
  • 26. Backplane • Redis • SQL Server • Azure Service Bus PM> Install-Package Microsoft.AspNet.SignalR.Redis public partial class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } GlobalHost.DependencyResolver.UseRedis("server", port, "password", "AppName");
  • 27. DEMO: Scale out with Redis
  • 28. Self host • Normally hosted in IIS • WHY self-hosted • No IIS • Performance issue • Console / Windows Form Application
  • 29. Self host - Server class Program { static void Main(string[] args) { using (WebApp.Start("http://localhost:8080")) { Console.ReadLine(); } } } class Startup { public void Configuration(IAppBuilder app) { app.UseCors(CorsOptions.AllowAll); app.MapSignalR(); } } PM> Install-Package Microsoft.AspNet.SignalR.SelfHost PM> Install-Package Microsoft.Owin.Cors
  • 30. Self host - Client <script type="text/javascript"> $(function () { $.connection.hub.url = "http://localhost:8080/signalr"; }); </script> PM> Install-Package Microsoft.AspNet.SignalR.JS <script src="~/scripts/jquery-1.6.4.min.js"></script> <script src="~/scripts/jquery.signalR-2.2.0.js"></script> <script src="http://localhost:8080/signalr/hubs"></script>
  • 31. Q & A

Editor's Notes

  1. https://channel9.msdn.com/Events/TechEd/NorthAmerica/2014/DEV-B416#fbid= https://channel9.msdn.com/Events/Build/2013/3-502
  2. http://www.asp.net/signalr/overview/getting-started/introduction-to-signalr http://owin.org/ http://www.asp.net/aspnet/overview/owin-and-katana/getting-started-with-owin-and-katana
  3. http://stackoverflow.com/questions/11077857/what-are-long-polling-websockets-server-sent-events-sse-and-comet http://nadirmuzaffar.blogspot.tw/2013/03/polling-long-polling-comet-server-side.html
  4. http://stackoverflow.com/questions/11077857/what-are-long-polling-websockets-server-sent-events-sse-and-comet http://nadirmuzaffar.blogspot.tw/2013/03/polling-long-polling-comet-server-side.html http://stackoverflow.com/questions/12078550/is-comet-obsolete-now-with-server-sent-events-and-websocket http://www.leggetter.co.uk/real-time-web-technologies-guide/realtime-web-technology-transport-mechanisms/
  5. http://cometdaily.com/2007/11/05/the-forever-frame-technique/
  6. http://stackoverflow.com/questions/11077857/what-are-long-polling-websockets-server-sent-events-sse-and-comet http://nadirmuzaffar.blogspot.tw/2013/03/polling-long-polling-comet-server-side.html
  7. http://stackoverflow.com/questions/11077857/what-are-long-polling-websockets-server-sent-events-sse-and-comet http://nadirmuzaffar.blogspot.tw/2013/03/polling-long-polling-comet-server-side.html
  8. http://www.asp.net/signalr/overview/getting-started/supported-platforms
  9. http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-server
  10. http://www.asp.net/signalr/overview/guide-to-the-api/handling-connection-lifetime-eventsr
  11. http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-server#route
  12. http://www.asp.net/signalr/overview/performance/scaleout-in-signalr http://www.tugberkugurlu.com/archive/scaling-out-signalr-with-a-redis-backplane-and-testing-it-with-iis-express
  13. http://www.asp.net/signalr/overview/performance/scaleout-with-sql-server http://www.asp.net/signalr/overview/performance/scaleout-with-redis http://www.asp.net/signalr/overview/performance/scaleout-with-windows-azure-service-bus
  14. http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host