• Save
SignalR: Add real-time to your applications
Upcoming SlideShare
Loading in...5
×
 

SignalR: Add real-time to your applications

on

  • 1,660 views

 

Statistics

Views

Total Views
1,660
Views on SlideShare
1,660
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

SignalR: Add real-time to your applications SignalR: Add real-time to your applications Presentation Transcript

  • SignalR: Add real-time to yourapplicationsby Eugene Zharkov
  • Why to use SignalR?https://github.com/SignalR/SignalR2
  • Transports• WebSockets (the only true full-duplex)• Server Sent Events• Forever Frame• Long polling
  • WebSockets• html5 feature• works on top of TCP protocol• full-duplex• low latency, low overhead• you need >IE10 and IIS8• not all browsers / servers/ proxies support it
  • Server Sent Events• requires a single connection between client-server• uses JS API EventSource through which client can request a particularURL to receive data stream• no need to reconnect• works in server-2-client direction only
  • Forever Frames• only for IE• hidden iframes are in the load loop with chunks of data6
  • Long Polling• high overhead on requests/response (headers etc.)• medium latency7
  • Transports8
  • Clients• iOS (SignalR-ObjC)• Android (SignalA)• Windows RT / Phone• jQuery, Backbone• Mono• QT (SignalR-QT)9
  • Requirements• Windows Server 2008 R2/2012, Windows 7/8• IIS 8. IIS 7 and 7.5. Support for extensionless URLs is required.• >= .NET 3.5, WinRT, Silverlight10
  • Does NOT support IE 6/711
  • Persistent Connection• the raw connection• IHTTP handler (OnConnection, OnDisconnection, OnReconnection)• custom logic must be implemented12
  • Hub• high-level API on top of Persistent Connection• route automatically mapped• clients can be divided by groups13
  • Add to project14
  • New References and Scripts15
  • Hub registration : C#public class MvcApplication : System.Web.HttpApplication{protected void Application_Start(){RouteTable.Routes.MapHubs();AreaRegistration.RegisterAllAreas();WebApiConfig.Register(GlobalConfiguration.ConfiguratFilterConfig.RegisterGlobalFilters(GlobalFilters.Fil01.02.03.04.05.06.07.08.16
  • Hub object | C#public class Documents : Hub{public void Send(string documentName){Clients.All.addMessage(documentName);}}01.02.03.04.05.06.07.17
  • Subscribe to Hub messages | JSvar documentHub = $.connection.documents;documentHub.client.addMessage = function (documentName) {$("#documents").append("<li>" + documentName + "</li>");};01.02.03.04.18
  • Hub object | JS$.connection.hub.logging = true;$.connection.hub.start().done(function () {$("#addDocument").click(function () {documentHub.server.send($("#document").val());});});01.02.03.04.05.06.19
  • Working with Hub | WinRTvar connection = new HubConnection("http://localhost:59576");var hub = connection.CreateHubProxy("documents");hub.On("addMessage", message =>Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>{DocumentsCounter.Text = (++_newDocuments).ToString();}));01.02.03.04.05.06.07.20
  • Working with Hub | Android (SignalA)HubConnection con = new HubConnection("http://localhost:59576this, new LongPollingTransport())IHubProxy hub = con.CreateHubProxy("documents");hub.On("addMessage", new HubOnDataCallback() {@Overridepublic void OnReceived(.. args) {{ //... }});con.Start();01.02.03.04.05.06.07.21
  • Thats all folks• @2j2e• eu.zharkov@gmail.com• http://bit.ly/signalr022