signal r
TRANSCRIPT
![Page 1: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/1.jpg)
Building Real Time Applications with ASP.NET SignalR
![Page 2: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/2.jpg)
Overview of SignalRConfigure SignalR and Visual StudioHubsConnectionsDeployment
Agenda
![Page 3: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/3.jpg)
Simplifies real time web development
ASP.NET Server and JavaScript Client Libraries
Real-time persistent connection abstraction over HTTP
Simplicity ReachPerformance
Overview: What is SignlaR?
"Incredibly simply real-time web for .NET"
– Damian Edwards, SignalR team
![Page 4: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/4.jpg)
OWIN http://owin.org/ Katana https://katanaproject.codeplex.com/
Overview: What is SignalR?
![Page 5: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/5.jpg)
Types of Apps Games, leaderboardsSocial ApplicationsBusiness CollaborationStocksChat, messagingDashboardsReal time formsAuctions
Anything that needs live data
Overview: Why Use SignalR?
![Page 6: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/6.jpg)
HTML & ASP.NET appsWindows Store & PhoneAny JavaScript client
Overview: Where you can use SignalR
![Page 7: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/7.jpg)
http://shootr.signalr.net http://JabbR.net
Overview: SignalR in Action
![Page 8: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/8.jpg)
http://www.asp.net/signalr NuGet package
OWIN References Scripts
GitHub download
Configure SignalR & Visual Studio
![Page 9: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/9.jpg)
SignalR Startupusing Owin;using Microsoft.Owin;[assembly: OwinStartup(typeof(SR3.Startup))]namespace SR3{ public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } }}
![Page 10: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/10.jpg)
SignalR setup
DEMO
![Page 11: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/11.jpg)
Microsoft.AspNet.SignalR.Hub http://msdn.microsoft.com/en-us/library/dn440565(v=vs.118).
aspx
Overview: SignalR Namespaces
![Page 12: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/12.jpg)
Microsoft.AspNet.SignalR.Hub classServer Side LibraryAllows for duplex connectivity
Hubs
![Page 13: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/13.jpg)
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 clientHubName attribute
Hubs
![Page 14: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/14.jpg)
Hub Eventspublic override Task OnConnected(){ var id = Context.ConnectionId; return base.OnConnected();}
![Page 15: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/15.jpg)
A full duplex, TCP based protocolIs not HTTPStandardized RFC in 2011
Hubs: Transports
![Page 16: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/16.jpg)
TransportsWebSockets is the only transport that establishes a true
persistent, two-way connection between client and server. SSE/EventsAJAX Long PollingForever Frame (IE only)
Transport selection process$.connection.hub.logging = true; // to determine transport
Hubs: Transports
![Page 17: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/17.jpg)
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
![Page 18: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/18.jpg)
Hubs
DEMO
![Page 19: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/19.jpg)
SignalR Client Script Libraries
<script src="~/Scripts/jquery.signalR-2.0.2.min.js"></script> <script src="~/signalr/hubs"></script>
@Scripts.Render("~/bundles/jquery")
SignalR depends on jQuery
SignalR script references
![Page 20: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/20.jpg)
Client SidePersistentConnection$.connection
Connections
![Page 21: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/21.jpg)
Hub to ConnectionConnection to HubConnection to ConnectionSpecific Connections
Connections: Communications
![Page 22: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/22.jpg)
Connecting to Hubs
DEMO
![Page 23: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/23.jpg)
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); }}
![Page 24: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/24.jpg)
Connecting to specific Hubs
DEMO
![Page 25: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/25.jpg)
Context.RequestHeadersQueryString
Send data via QueryString
// .NET clientvar connection = new HubConnection("http://localhost:8080/", "data=12345");
// JavaScript client $.connection.hub.qs = "data=12345";
// Hub server codevar qs = Context.Request.QueryString["myInfo"].ToString();
![Page 26: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/26.jpg)
Notify the client of slow or unavailable connectivity
Connection Status
$.connection.hub.connectionSlow(function () { notifyUserOfConnectionProblem(); })$.connection.hub.reconnecting(function () { notifyUserOfReconnection(); });
![Page 27: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/27.jpg)
Azure SDKDeployment To-Do's
Enable WebSocketsEnable V 4.5
Multiple Azure instanceshttp://
www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/using-signalr-with-windows-azure-web-sites
SignalR Deployment
![Page 28: Signal r](https://reader035.vdocuments.mx/reader035/viewer/2022062503/588279a41a28ab24788b5127/html5/thumbnails/28.jpg)
Thank You!