developing real time web apps with signalr - js-il.com
Post on 10-May-2015
759 Views
Preview:
DESCRIPTION
TRANSCRIPT
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Developing “Real-Time” Web Applications
with SignalR
Israel JavaScript Conference
Yaniv YechezkelYaniv@UpStruct.nethttp://www.UpStruct.net
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Israel JavaScript Conference
Yaniv YechezkelYaniv@UpStruct.nethttp://www.UpStruct.net
Hello.
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Agenda Introduction to SignalR Real-Time Web Getting Started with SignalR Simplicity Reach Performance Extensibility Security Reference Project
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Introduction to SignalR
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
What is ASP.NET SignalR? ASP.NET SignalR is a library for ASP.NET
developers that simplifies the process of adding real-time web functionality to applications.
Real-time web functionality is the ability to have server code push content to connected clients instantly as it becomes available, rather than having the server wait for a client to request new data.
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Who is Behind SignalR? Damian Edwards & David Fowler,
Both from Microsoft, started it as a “Side Project”…
Now officially part of ASP.NET.
Open-Source.
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Real-Time Web
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Real-Time Web But we know the web, and by that we
mean HTTP, is based on the Request/Reply Paradigm, right?
Response
Request
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Real-Time Web Real-Time: Web UI that updates in real-
time
Server Push: Push messages to connect clients
COMET: An umbrella for existing HTTP push techniques
HTTP Streaming: Another name for COMET
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
HTML 5 Changes The Rules of The Game
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Web Socket Protocol Handshake
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Getting Started
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Get The Bytes Get Visual Studio 2012 Update 2
(VS2012.2)http://www.microsoft.com/en-us/download/details.aspx?id=38188
Download via NuGet
Or, get the Source from GitHubhttps://github.com/SignalR/SignalR
install-package Microsoft.AspNet.SignalR
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Stock Ticker Sample
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Moving Shape
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
What is ASP.NET SignalR? Real-Time, persistent connection
abstractionover HTTP for .NET.
Supported Transports/Techniques
- Web Sockets- Server Sent Events (Event Source)- Forever Frame- Ajax Long Polling
3 Pillars – Simplicity, Reach, Performance
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Not Just for Chat Dashboards and Monitoring Collaboration of any kind Job Progress Gaming More…
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Examples ShootR (Shooting Game)
http://shootr.signalr.net
JabbR (Chat)https://jabbr.net
BromeLard (Collaborative Maps)http://www.bromelard.com
Morehttps://github.com/SignalR/SignalR/wiki/Projects-Using-SignalR
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Simplicity: Two Level API Connections
- Low Level
Hubs- Built on top of connections- RPC from client-server and server-client- Automatic Proxy generation
Choose the level of abstraction that works for you.
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Hubs – An RPC IllusionPublisher (Caller)
Subscriber (Others)
hub.server.moveShape(x, y);
hub.client.shapeMoved = function (x, y) { shape.css({left: x,top: y});}
Hub
[HubMethodName("moveShape")]public void MoveShape(int x, int y){ Clients.Others.shapeMoved(x, y);}
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Auto-Generated Proxy<script src="/ signalr/hubs"></script>
HubConfiguration cfg = new HubConfiguration(){ EnableJavaScriptProxies = true};
RouteTable.Routes.MapHubs(“~/signalr”, cfg );
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Reach: What about Web Sockets? ASP.NET 4.5 on Windows Server 2012 IE 10 or Latest Chrome, FF, Safari Load Balancer/Reverse Proxy supports it Client Proxy server/NAT supports it Everybody in between supports it You find programming raw sockets is fun You manage scaleout yourself
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Reach: What about Web Sockets?
Web Browser Transport Requirements
http://www.asp.net/signalr/overview/getting-started/supported-platforms
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Reach: SignalR Works Everywhere Tries Web Sockets, but then fallback to:
- Server Sent Events (Event Source)- Forever Frame- Ajax Long Polling
Powerful API
Holds the connection opened.
Scales-Out
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Reach: Not Just Web Clients JavaScript (jQuery) .NET 4.0/4.5 Silverlight 5 Windows Store Apps Windows Phone 8 iOS More coming…
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Transports
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Performance
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Performance: Throughput & Scale On a single Extra Large Windows Azure
Box~500,000 Msg/Sec
On a single Box>100,000 Concurrent Connections
Client Load Generatorhttps://github.com/SignalR/SignalR/wiki/Performance
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Performance: Scale-Out
3 Supported Backplanes- Windows Azure Service Bus- Redis (In-Memory Pub/Sub)- SQL Server
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Extensibility
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Dependency Injection Derive from DefaultDependencyResolver
Found In Microsoft.AspNet.SignalR.
Replace Resolver before initializing the Hub
GlobalHost.DependencyResolver = new SignalRUnityResolver(m_Container);
RouteTable.Routes.MapHubs(cfg );
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Hub Pipeline Much like MVC Filters, or HTTP Modules,
You can intercept the Hub Pipeline…public class TraceModule: HubPipelineModule{ protected override void OnAfterConnect(IHub hub) { Debug.WriteLine(hub.Context.ConnectionId); base.OnAfterConnect(hub); }}
GlobalHost.HubPipeline.AddModule( new TraceModule());
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Security
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
How to Handle Security? Implement the Authentication outside
the Hub. For example, in an MVC Controller.
As the Hub is actually running under same HttpContext, any Principal your place in the Pipeline will be available, and thus enforced. [Authorize(Roles = "LiveId")][HubMethodName("chat")]public void Chat(ChatMessage message){}
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Reference Project
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Mobile Social Online Game
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Summary Easy API to get start with.
Supported on Windows Azure VM’s and Cloud Services.
Not limited just to Web Clients.
Real-Time becomes a real thing.
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Resources Official Site
http://www.asp.net/signalr
WIKIhttps://github.com/SignalR/SignalR/wiki
JabbRhttps://jabbr.net
ASP.NET SignalR Book (free)http://www.campusmvp.net/signalr-ebook
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
www.js-il.com
18.6.13
Israel JavaScript Conference | 03 – 6325707 | info@e4d.co.il | www.js-il.com |
Thanks
Yaniv YechezkelYaniv@UpStruct.nethttp://www.UpStruct.net
top related