Echt jetzt?! Echtzeitanwendungen für das Web mit SignalR. Tobias Krügel. Conplement AG

Ähnliche Dokumente
Rapid Response UI mit WebSockets

Realtime Anbindung an SAP ERP

ORACLE. EXPERTISE. PASSION.

Embedded Webserver in Forth

Websockets: Leichtgewichtige Verbindungen für Web-Applikationen

Web APIs auf dem Prüfstand Volle Kontrolle oder fertig mit den Azure Mobile Services?

Google Gears Offline Web?

Vorstellung der Studienarbeit zum Thema Websockets. Christian Linha. IF6

Java Tools JDK. IDEs. Downloads. Eclipse. IntelliJ. NetBeans. Java SE 8 Java SE 8 Documentation

Websockets. Verbindungskanal zwischen Client-Anwendung (JavaScript in Browser) und Server.

Die Alternative zum Web-Form Modell

Unified-E Standard WebHttp Adapter

Web Sockets mit HTML5. Quelle:

Hypertext Transfer Protocol

MULTIPLEXING UND SERVER PUSH

Web-basierte Anwendungssysteme PHP-Einführung

Mobile Web-Technologien. Interaktionen und

Delphi MVC Framework. Mathias Pannier

NotesSession.GetPropertyBroker( )

Vorteil. Einfach zu realisieren performant. Übersichtlich performant. "Vererbung" von Änderungen an vererbender Tabelle

15. Das Hypertext Transfer Protokoll HTTP - Überblick. 1. Requests und Responses. 2. Content Negotiation. 3. State Management (Cookies)

39 Object Request Brokers. 40 Components of an ORB Stubs and Skeletons Stub

The app the crashes, before the breakpoint is reached: Code to the event:

Anmeldung am FRITZ!Box Webinterface

Node.js Einführung Manuel Hart


Creating OpenSocial Gadgets. Bastian Hofmann

39 Object Request Brokers

SIP: Session Initiation Protocol (Signalisierungsprotokoll für Sessions) Request. Response

Android VPN. Am Beispiel eines Netzwerktunnels für das Domain Name System (DNS) 1 Andiodine - Android DNS-VPN

SODA. Die Datenbank als Document Store. Rainer Willems. Master Principal Sales Consultant Oracle Deutschland B.V. & Co. KG

JavaScript AJAX. Univ.-Prof. Dr.-Ing. Wolfgang Maass. Chair in Information and Service Systems Department of Law and Economics

REST-API mit Node, Express und MongoDB

Studienarbeit im Fach Aktuelle Technologien zur Entwicklung Verteiler Java Anwendungen

Java - Webapplikationen

NILS HARTMANN OLIVER ZEIGERMANN EINSTIEG IN. React.

Webentwicklung mit Vaadin 7. Theoretische und praktische Einführung in Vaadin 7. Christian Dresen, Michael Gerdes, Sergej Schumilo

Mail: Web: juergen-schuster-it.de

P2P Content Sharing mit WebRTC. Christian Vogt - Max Jonas Werner -

Modul 9: Web APIs (REST, XHR, SSE, WebSockets)

Pylons & ExtJS. PyCologne Vortrag Köln, smart:elligence Unternehmensberatung, Düsseldorf

39 Object Request Brokers

Umzug. ASP.NET-WebForms-Elemente in MVC weiterverwenden. Dr. Malte Clasen adesso AG

Auszug aus Axis2 Schulung

Komponentenorientierte Software-Entwicklung. Seite 1 / 42

synedra View Embedded Michael Doppler, synedra it GmbH

NEWSLETTER. FileDirector Version 2.5 Novelties. Filing system designer. Filing system in WinClient

CS1024 Internetbasierte Systeme

Nerdball Ein automatischer IRC Image Collector


Varnish + TYPO3. CH-TUG Varnish + TYPO3

HERZLICH WILLKOMMEN SHAREPOINT 2013 DEEP DIVE - APPS IOZ AG 1

vcdm im Wandel Vorstellung des neuen User Interfaces und Austausch zur Funktionalität V

!!!! Mail: Web: juergen-schuster-it.de. ! APEX D-A-CH Facebook Group: bit.ly/apex_on_facebook

Cameraserver mini. commissioning. Ihre Vision ist unsere Aufgabe

What s New? Skype for Business. Dirk THORMANN

Perl-Praxis. CGI-Skripte. Jörn Clausen Jens Reeder, Jan Krüger

REST Services To-Go Einfacher Einstieg in die REST Programmierung

{ Light up the Web } Oliver Scheer. Evangelist Microsoft Deutschland

Legacy Web-Apps mit AngularJS pimpen

Microservices. - Integration der Benutzeroberfläche - Version: Orientation in Objects GmbH. Weinheimer Str.

ASP.NET 3.5 mit AJAX

HTTP/2. Mirko Dziadzka. OWASP Stammtisch München

HERZLICH WILLKOMMEN SHAREPOINT 2013 DEEP DIVE APPS IOZ AG 1

.NET als Microsofts Entwicklerplattform

Protokolle. Konrad Rosenbaum, 2006/7 protected under the GNU GPL & FDL

.NET-Networking 2 Windows Communication Foundation

Microservice UI Composition

23. Januar, Zürich-Oerlikon

So legen Sie eine gelöschte Resource wieder an

Auszug aus JAX-WS Folien

Microservices Integration der Benutzeroberfläche

Backend. Hochschule Darmstadt, Fachbereich Informatik, Wintersemester 2016/2017. Christopher Dörge, Thomas Sauer, David Müller

Perl-Praxis. CGI-Skripte. Madis Rumming, Jan Krüger.

Fakultät für Informatik & Wirtschaftsinformatik DB & IS II SS 2015 PHP MVC. Dr. Christian Senger. PHP MVC 1 von 21

OSGI DECLARATIVE SERVICES

Der Inhalt dieses Foliensatzes ist nicht klausurrelevent!!! - aber trotzdem interessant ;-)

WebSockets: Spezifikation / Implementierung

Kurzanleitung RMI-Beispiel: gettime Seite 1 / 7. RMI Projekt gettime 1

Anwendungsprotokolle: HTTP, POP, SMTP

Microservices Integration der Benutzeroberfläche

NATURAL FOR AJAX RESPONSIVE WEB ANWENDUNGEN FÜR MOBILE ENDGERÄTE ROLAND FABICH NOVEMBER 2016

2. WWW-Protokolle und -Formate

SSL Installation auf Lotus Domino 8.5

Forschungsseminar Web VSR Betreuer Michael Krug

OSGI DECLARATIVE SERVICES

Übung 1 mit C# 6.0 MATTHIAS RONCORONI

Destructive AJAX. Stefan Proksch Christoph Kirchmayr

Webengineering. jquery

APEX DESKTOP APPS. Interaktion mit dem Client System

Oracle9i Designer. Rainer Willems. Page 1. Leitender Systemberater Server Technology Competence Center Frankfurt Oracle Deutschland GmbH

Device Management Schnittstellen. Referat von Peter Voser Embedded Development GmbH

Mobile Backend in der

Watson Collaborator Cognitive Training für Collaboration Solutions

Rails Ruby on Rails Ajax on Rails. Clemens H. Cap

Perl-Praxis. CGI-Skripte. Jörn Clausen

Wie ich lernte die API zu lieben. 19. März sic[!]sec GmbH Industriestraße Gröbenzell

Graphische Benutzeroberflächen mit Matlab

Transkript:

Echt jetzt?! Echtzeitanwendungen für das Web mit SignalR Tobias Krügel Conplement AG

Einführung 2 conplement AG 2010. All Rights Reserved.

Agenda Communication Strategies SignalR API Server Client Demo 3 conplement AG 2010. All Rights Reserved.

Agenda Communication Strategies 4 conplement AG 2010. All Rights Reserved.

Communication Strategies Problem Web Communication = HTTP HTTP eignet sich nicht für Push Benachrichtigungen (Request, Response) Wie können Push Notifications für Web- Anwendungen realisiert werden? 5 conplement AG 2010. All Rights Reserved.

Communication Strategies Lösungsansätze Periodic Polling Long Polling Forever Frame Server-Sent Events (SSE) SignalR WebSockets 6 conplement AG 2010. All Rights Reserved.

Communication Strategies Periodic Polling Client Server request while(true) t data data response 7 conplement AG 2010. All Rights Reserved.

Communication Strategies Long Polling Client Server t t request response request empty response wait for data or timeout data wait for data or timeout request http://msdn.microsoft.com/de-de/magazine/hh882442.aspx 8 conplement AG 2010. All Rights Reserved.

Communication Strategies Forever Frame (Reverse Ajax) Client Server run JavaScript 5 7 9 iframe 1 2 request <html> response <head></head> <body> <iframe src="http://www.cp.de"></iframe> </body> </html> 3 request (iframe) <script type="text/javascript"> (function () { //... })(); </script> response (chunk) 8 4 6 Responseheader: Transfer-Encoding: chunked http://en.wikipedia.org/wiki/comet_%28programming%29 9 conplement AG 2010. All Rights Reserved.

Communication Strategies Server-Sent Events Client Server var source = new EventSource("/stream"); source.addeventlistener("message", function(msg) { }); Accept: text/event-stream Cache-Control: no-cache Connection: keep-alive event: message data: "hello world" Content-Type: text/event-stream Cache-Control: no-cache Connection: keep-alive 10 conplement AG 2010. All Rights Reserved. http://www.html5rocks.com/en/tutorials/eventsource/basics/?redirect_from_locale=de http://en.wikipedia.org/wiki/server-sent_events http://dev.w3.org/html5/eventsource/

Communication Strategies Server-Sent Events http://caniuse.com/ 11 conplement AG 2010. All Rights Reserved.

ws http Communication Strategies Web Socket Client GET /mychat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: <key> Sec-WebSocket-Protocol: chat Sec-WebSocket-Version: 13 Origin: http://example.com HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: <key> Sec-WebSocket-Protocol: chat Server <key> + 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 + SHA-1 12 conplement AG 2010. All Rights Reserved. http://en.wikipedia.org/wiki/websocket http://www.html5rocks.com/de/tutorials/websockets/basics/

Communication Strategies Web Socket http://caniuse.com/ 13 conplement AG 2010. All Rights Reserved.

Agenda Server-API 14 conplement AG 2010. All Rights Reserved.

Hubs Beispiel using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hubs; namespace SignalR.Hubs { [HubName("chat")] public class ChatHub : Hub { public void SendMessage(string message) { Clients.All.newMessage(message); } } } ASP.NET and Web Tools 2012.2 update 15 conplement AG 2010. All Rights Reserved.

Hubs IHub namespace Microsoft.AspNet.SignalR.Hubs { public interface IHub : IDisposable { Task OnConnected(); Task OnReconnected(); Task OnDisconnected(); HubConnectionContext Clients { get; set; } HubCallerContext Context { get; set; } } } IGroupManager Groups { get; set; } 16 conplement AG 2010. All Rights Reserved.

Hubs Client Property // Represents the calling client Clients.Caller.newMessage(message); // All connected clients except the calling client Clients.Others.newMessage(message); // All connected clients Clients.All.newMessage(message); // Returns a dynamic representation of all clients except the calling client ones specified Clients.AllExcept("ConnectionId-1", "ConnectionId-2").newMessage(message); // Returns a dynamic representation of the connection with the specified connection Id Clients.Client("ConnectionId-1").newMessage(message); // Returns a dynamic representation of a group Clients.Group("groupName", "ConnectionId-1", "ConnectionId-2").newMessage(message); // Returns a dynamic representation of all clients in a group except the calling client Clients.OthersInGroup("groupName").newMessage("message"); 17 conplement AG 2010. All Rights Reserved.

Hubs Context Property // Gets the connection ID of the calling client string id = Context.ConnectionId; // Gets the headers for the request NameValueCollection headers = Context.Headers; // Gets the query string for the request NameValueCollection query = Context.QueryString; // Gets the IRequest for the current request IRequest request = Context.Request; // Gets the cookies for the request IDictionary<string, Cookie> cookies = Context.RequestCookies; // Gets the IPricipal for the request IPrincipal user = Context.User; 18 conplement AG 2010. All Rights Reserved.

Hubs Groups Property // Registers the client with the given connection id to // the group with the given group name. // If the groups doesn't exist, create a new group with // the given name first. Groups.Add(Context.ConnectionId, groupname); // Removes the client with the given connection Id from // the group with the given group name. Groups.Remove(Context.ConnectionId, groupname); 19 conplement AG 2010. All Rights Reserved.

Routing Configuration public static void RegisterRoutes(RouteCollection routes) { HubConfiguration configuration = new HubConfiguration { EnableCrossDomain = true, EnableDetailedErrors = false, EnableJavaScriptProxies = true, Resolver = new DefaultDependencyResolver() }; } RouteTable.Routes.MapHubs(configuration); routes.maproute( url: "{controller}/{action} ", defaults: new { controller = "Home", action = "Index"} ); Registriet die von SignalR benötigten Routes: ~/signalr ~/signalr/hubs ~/signalr/negotiate ~/signalr/transport 20 conplement AG 2010. All Rights Reserved.

Agenda Client-API 21 conplement AG 2010. All Rights Reserved.

Proxies Auto generated Static Programmatically 22 conplement AG 2010. All Rights Reserved.

Proxies Auto generated Proxy HubConfiguration configuration = new HubConfiguration { EnableJavaScriptProxies = true // Default }; Hubs müssen vor(!) allen anderen RouteTable.Routes.MapHubs(configuration); Routes definiert werden. <script src="~/scripts/jquery.signalr-1.0.1.js"></script> <script src="signalr/hubs"></script> <script type="text/javascript"> $(function () { var chat = $.connection.chat; $.connection.hub.start({transport: "longpolling"}); }); </script> Löst negotiation aus und stellt die Verbindung über eine Technologie (Long Polling etc.) her Liefert JavaScript Code, der sofort ausgeführt wird und die Hubs am Client registriert "websockets" "foreverframe" "serversentevents" "longpolling" 23 conplement AG 2010. All Rights Reserved.

Proxies Client API // Connection for all hubs var connection = $.connection.hub; // Returns a client side hub from the proxy var chathub = connection.proxies.chat; var chathub = $.connection.chat; // Register client side callback (called from Server via Clients.All.addMessage("text"); chathub.client.addmessage = function(msg) { /*... */ }; // Call a server side method chathub.server.sendmessage("text").done(function () { /*... */ }).fail(function () { /*... */ }); // Start the connection (starts negotiation) $.connection.hub.start({ transport: "longpolling" }).done(function () { /*... */ }).fail(function () { /*... */ }); 24 conplement AG 2010. All Rights Reserved.

Proxies Static Proxy (1/2) Erzeugtes File muss in View Referenziert werden!!! 25 conplement AG 2010. All Rights Reserved.

Proxies Static Proxy (2/2) <script src="~/scripts/jquery.signalr-1.0.1.js"></script> <script src="~/scripts/server.js"></script> <script type="text/javascript"> $(function () { var chat = $.connection.chat; $.connection.hub.start(); }); </script> Liefert ein statische JavaScript-File mit Hubs und Code, der sofort ausgeführt wird und die Hubs am Client registriert Löst negotiation aus und stellt die Verbindung über eine Technologie (Long Polling etc.) her 26 conplement AG 2010. All Rights Reserved.

Proxies Programmatic Proxy <script src="~/scripts/jquery-1.7.1.js"></script> <script src="~/scripts/jquery.signalr-1.0.1.js"></script> <script type="text/javascript"> $(function () { var connection = $.hubconnection(); var proxy = connection.createhubproxy("chat"); proxy.on("broadcast", function (message) { $("#output").append(message); }); }); connection.start().done(function () { $("#send").click(function () { proxy.invoke("send", $("#message").val()) } ); }); </script> 27 conplement AG 2010. All Rights Reserved.

Agenda Roundtrip 28 conplement AG 2010. All Rights Reserved.

Roundtrip Client Server http://localhost:20716 Index.html http://localhost:20716/signalr/hubs $.connection.hub.start() Gets possible Communication strategy hubs.js (Proxies) http://localhost:20716/signalr/negotiate 200 OK http://localhost:20716/signalr/connect?transport=webs ockets 101 Switching Protocols 1. Web Socket 2. Server-Sent Events 3. Forever Frame 4. Long Polling 29 conplement AG 2010. All Rights Reserved.

Agenda Ausblick 30 conplement AG 2010. All Rights Reserved.

Ausblick SignalR Clients Browser Windows Phone 8 WPF / WebForms Hosting ASP.NET Self Hosting Windows Azure Websites 31 conplement AG 2010. All Rights Reserved.

Quellen Longpolling: http://msdn.microsoft.com/de-de/magazine/hh882442.aspx Forever Frame: http://en.wikipedia.org/wiki/comet_%28programming%29 Server Sent Events: http://www.w3schools.com/html/html5_serversentevents.asp http://www.worldwidewhat.net/2011/07/using-server-sent-events-with-asp-net/ http://html5doctor.com/server-sent-events/ http://www.html5rocks.com/en/tutorials/eventsource/basics/?redirect_from_locale=de http://en.wikipedia.org/wiki/server-sent_events http://dev.w3.org/html5/eventsource/ Web Sockets: http://en.wikipedia.org/wiki/websocket http://www.html5rocks.com/de/tutorials/websockets/basics/ SignalR: http://signalr.net/ http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-javascript-client http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc-4 32 conplement AG 2010. All Rights Reserved.

Agenda Vielen Dank! Tobias Krügel conplement AG Tobias.kruegel@conplement.de 33 conplement AG 2010. All Rights Reserved.