SlideShare a Scribd company logo
Ch’ti JUG
            HTML5 Communication
              Building Real-Time
            Applications with HTML5
                  Web Sockets
                  Ch'ti Java User Group
                   http://chtijug.org/

                                       Peter Lubbers, Kaazing
                                         10 December 2009

              Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
Ch’ti JUG        Qui C’est Ce Mec?
            Peter Lubbers
            • Director of documentation
              and training at Kaazing
            • Skills Matter and Zenika
              HTML5 training courses
            • Co-author Apress Book
              Pro HTML5 Programming
              (Spring 2010)
            • Ultramarathon runner, blogger
              runlaketahoe.blogspot.com
                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                                              Agenda
            • Introduction
            • History of the real-time Web
            • WebSocket and Server-Sent Events
            • Cross-Document Messaging and
              XHR Level 2
            • Beyond WebSocket
            • Questions?




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                     Today’s Requirements
            • Today’s Web applications demand
              reliable, real-time communications with
              near-zero latency
            • Examples:
               • Financial applications
               • Social networking applications
               • Online games
               • Smart power grid

                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                              HTTP Limitations
            • Until now, this has been cumbersome to
              achieve, primarily due to the limitations
              of HTTP
            • HTTP is half-duplex (traffic flows in only
              one direction at a time)
            • HTTP is a stateless, request-driven
              protocol




                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                              HTTP Limitations
            • Header information is sent with each
              HTTP request and response, which can
              be an unnecessary overhead
            • After a response is sent, the server may
              choose to close the socket
            • Rich Internet Applications (with Ajax,
              Comet, Silverlight, and Flash) are
              becoming richer, but still limited by
              HTTP

                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                                Ajax and Comet
            • Ajax (Asynchronous JavaScript and
              XML) is a technique for building highly
              interactive applications for the Web
            • Content can change without loading the
              entire page
            • Ajax Delivers:
              • User-perceived low latency
              • Single page
            • “Real-time” often achieved through
              polling and long-polling (Comet)
                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                                               Polling
            • Polling is “nearly real-time”
            • Sometimes used in Ajax applications to
              simulate real-time communication
            • Browser sends HTTP requests at regular
              intervals and immediately receives a
              response




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                   Polling Architecture




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                                      Long Polling
            • Also known as asynchronous-polling
            • Browser sends a request to the server
              and the server keeps the request open for
              a set period.
            • HTTP headers, present in both long-
              polling and polling often account for
              more than half of the network traffic.




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Long Polling Architecture




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                                          Streaming
            • More Efficient, but still not perfect
            • Possible complications:
               • Proxies and Firewalls
               • Response builds up and must be flushed
                 periodically
               • Cross-domain issues to do with browser
                 connection limits




                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Half-Duplex Architecture




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
             Streaming Architecture




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
             Current Approaches Are…




                Fake Time!
            Or: Not Really Time
              Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Example of Polling in Action




                Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            HTTP Header Overhead




              Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG       Example HTTP Request
            GET /PollingStock//PollingStock HTTP/1.1
            Host: localhost:8080
            User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
               rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5
            Accept:
               text/html,application/xhtml+xml,application/xml;q=0.9,*/*;
               q=0.8
            Accept-Language: en-us
            Accept-Encoding: gzip,deflate
            Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
            Keep-Alive: 300
            Connection: keep-alive
            Referer: http://localhost:8080/PollingStock/
            Cookie: showInheritedConstant=false;
               showInheritedProtectedConstant=false;
               showInheritedProperty=false;
               showInheritedProtectedProperty=false;
               showInheritedMethod=false;
               showInheritedProtectedMethod=false;
               showInheritedEvent=false; showInheritedStyle=false;
               showInheritedEffect=false
                    Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
               Example HTTP Response
            HTTP/1.x 200 OK
            X-Powered-By: Servlet/2.5
            Server: Sun Java System Application Server 9.1_02
            Content-Type: text/html;charset=UTF-8
            Content-Length: 321
            Date: Sat, 07 Nov 2009 00:32:46 GMT




                    Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            HTTP Header Traffic Analysis
            • Example network throughput for Polling
              HTTP request and response headers:
              • Use case A: 10,000 clients polling every 60
                seconds:
                 • Network throughput is (871 x 10,000)/60 = 145,166
                   bytes = 1,161,328 bits per second (1.1 Mbps)
              • Use case B: 10,000 clients polling every second:
                 • Network throughput is (871 x 10,000) = 8,710,000
                   bytes = 69,680,000 bits per second (66 Mbps)
              • Use case C: 100,000 clients polling every 10
                seconds:
                 • Network throughput is (871 x 100,000)/10 = 8710000
                   bytes = 69,680,000 bits per second (66 Mbps)
                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Network Throughput Comparison




                Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Technology-Specific Problems
            • AJAX
              • Enables clients to asynchronously poll for
                server-side events (at best)
              • Polling leads to poor resource utilization on
                both the client and server
            • Comet
              • Lack of a standard implementation
              • Often requires complex techniques such as
                multiplexing or managing multiple domains



                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                              Headache 2.0




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                        Desktop vs. Browser
            • Desktop Networking
              • Full-duplex bidirectional TCP sockets
              • Access any server on the network
            • Browser Networking
              • Half-duplex HTTP request-response
              • HTTP polling, long polling fraught with
                problems




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                 Desktop Architecture




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                                   About HTML5
            • HTML5 is the next set of W3C HTML
              standards
            • It offers new and enhanced features to
              address new HTML primitives,
              multimedia, offline use, communication,
              and so on
            • Many of the browser vendors have
              already implemented several of these
              features


                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                               HTML5 Features
            • HTML5 includes a wide range of new
              features, including:
              •   Canvas
              •   Workers
              •   Geolocation
              •   New form elements
              •   Offline storage
              •   Communication APIs
              •   And more…


                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
              HTML5 Communication
            • WebSocket
              • Proxy/Firewall-friendly text socket for
                browsers
            • Server-Sent Events
              • Standardized HTTP streaming (downstream)
            • XMLHttpRequest Level 2
              • Cross-origin XMLHttpRequest
            • Cross Document Messaging
              • Secure inter-window (iframe)
                communication
                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Part of the HTML5 Spec?
            • Web Sockets—like other pieces of the
              HTML5 effort such as Local Storage and
              Geolocation—was originally part of the
              HTML5 specification
            • Moved to a separate standards document
              to keep the specification focused
            • Web Sockets has been submitted to the
              Internet Engineering Task Force (IETF)
              by its creators, the WHATWG


                 Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG      HTML5 WebSockets
            • HTTP-friendly TCP for the browser with
              minimal framing
            • Full-duplex bidirectional communication
            • Operates over a single socket
            • Distributed client-server architecture
            • No browser plug-ins
            • Traverses proxies and firewalls seamlessly
            • Allows authorized cross-origin
              communication

                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            WebSocket Architecture




               Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG      HTML5 WebSockets

            • Connection established by upgrading
              from the HTTP protocol to the WebSocket
              protocol using the same TCP connection
            • WebSocket data frames can be sent back
              and forth between the client and the
              server in full-duplex mode




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG   HTML5 WebSocket Schemes
            • WebSocket
              ws://www.websocket.org/text
            • WebSocket Secure
              wss://www.websocket.org/encrypted-text




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            HTML5 WebSocket Handshake
             GET /text HTTP/1.1rn
             Upgrade: WebSocketrn
             Connection: Upgradern
             Host: www.websocket.orgrn
             …rn

             HTTP/1.1 101 WebSocket Protocol
             Handshakern
             Upgrade: WebSocketrn
             Connection: Upgradern
             …rn


                 Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                    HTML5 WebSocket Frames
            • Text and binary frames can be sent full-duplex, in either
              direction at any the same time
            • Each frame of data:
                •   Starts with a 0x00 byte
                •   Ends with a 0xFF byte
                •   Contains UTF-8 data in between
            • Text Frames use terminator
                •   x00Hello, WebSocket0xff
            • Binary Frames use length prefix:
                •   x000x10Hello, WebSocket
            • There is no defined maximum size
                •   If the user agent has content that is too large to be handled, it
                    must fail the Web Socket connection
                •   JavaScript does not allow >4GB of data, so that is a practical
                    maximum
                     Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
              Drastic Reduction in Network
                         Traffic
            • With WebSocket, each frame has only 2
              bytes of packaging (compare almost 500:1
              or even 1000:1)
            • No latency involved in establishing new
              TCP connections for each HTTP message
            • Remember the Polling HTTP header traffic
              (66 Mbps network throughput for headers
              alone)?


                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            HTTP Header Traffic Analysis
            • Example network throughput for
              WebSocket HTTP request and response
              headers:
              • Use case A: 10,000 frames every 60 seconds:
                 • Network throughput is (2 x 10,000)/60 = 333 bytes =
                   2,664 bits per second (2.6 Kbps)
              • Use case B: 10,000 frames every second:
                 • Network throughput is (2 x 10,000) = 20,000 bytes =
                   160,000 bits per second (156 Kbps)
              • Use case C: 100,000 frames every 10 seconds:
                 • Network throughput is (2 x 100,000)/10 = 20,000
                   bytes = 160,000 bits per second (156 Kbps)

                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Network Throughput Comparison




                Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                                     Overheard…
            "Reducing kilobytes of data to 2
             bytes…and reducing latency from 150ms
             to 50ms is far more than marginal. In
             fact, these two factors alone are enough
             to make WebSocket seriously interesting
             to Google.“
             —Ian Hickson (Google, HTML5 spec lead)




                 Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG   HTML5 WebSockets API

            • Creating a WebSocket instance:
              var myWebSocket = new WebSocket
                (“ws://www.websocket.org”);




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG   HTML5 WebSockets API
            • Associating listeners
              myWebSocket.onopen = function(evt) {
                alert(“Connection open ...”); };
              myWebSocket.onmessage =
                function(evt) { alert( “Received
                Message: ” + evt.data); };
              myWebSocket.onclose = function(evt)
                { alert(“Connection closed.”); };




                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG   HTML5 WebSockets API

            • Sending messages
              myWebSocket.send(“Hello
                WebSocket!”);
              myWebSocket.close();




                 Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                             Browser Support
            • Chromium support added just a few weeks
              ago (nightly builds)
            • Webkit activity




                 Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                Native WebSocket in Chromium

            :




                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
             HTML5 Server-Sent Events

            • Standardizes and formalizes how a
              continuous stream of data can be sent
              from a server to a browser
            • Introduces EventSource—a new
              JavaScript API




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
               SSE Architecture




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG         EventSource API

            • Connects to a server URL to receive an event
              stream:
              var stream =
                new EventSource("http://news.kaazing.com");


            • Set event handlers:
              stream.onopen = function() { alert(“open”); }
              stream.onmessage = function(event) {
                     alert(“message: “ + event.data); }
              stream.onerror = function() { alert(“error”);
                }



                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                             Browser Support

            • Partial support in Opera 9+
            • Development in Firefox trunk




                 Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                  XMLHttpRequest Level 2
            • XMLHttpRequest is the API that made Ajax
              possible
            • XMLHttpRequest Level 2 significantly
              enhances XMLHttpRequest
            • Improvements in the following areas:
              • Progress events
              • Cross-origin XMLHttpRequests




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                     Progress Events
            • XMLHttpRequest Level 2 supports named
              progress events:
              •   loadstart
              •   progress
              •   abort
              •   error
              •   load
              •   loadend
            • readyState property and
              readystatechange events retained for
              backward compatibility
                    Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                       Progress Events
            • Progress events have fields for:
              • The total amount of data to transfer
              • The amount that has already transferred
              • Whether the total is known (Boolean value)
            • Example:
              crossOriginRequest.upload.onprogress = function(e) {
                  var total = e.total;
                  var loaded = e.loaded;


                  if (e.lengthComputable) {
                           // do something with the progress information
                  }
              }

                      Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Cross-Origin XMLHttpRequest
            • XMLHttpRequest Level 2 allows for cross-
              origin XMLHttpRequests using Cross
              Origin Resource Sharing (CORS)
              http://www.w3.org/TR/access-
                 control/
            • Example:
              var crossOriginRequest = new
                XMLHttpRequest();
              crossOriginRequest.open("GET",
                "http://www.example.net/stockfeed",
                true);

                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG          Origin Security
            • An origin is a subset of an address used for
              modeling trust relationships on the Web
            • Origins are made up of a scheme, a host, and
              a port—different origin:
              • https://www.example.com
              • http://www.example.com
            • The path is not considered in the origin
              value—same origin:
              • http://www.example.com/index.html
              • http://www.example.com/page2.html


                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG          Origin Security
            • Cross-origin communication identifies the
              sender by origin
              • Allows receiver to ignore messages from
                origins it does not trust or does not expect to
                receive messages from (white list)
              • Applications must opt-in to receiving
                messages by adding an event listener for
                message events
              • No risk of messages interfering with an
                unsuspecting application



                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                  Preflight Requests
            • For sensitive actions (for example, a
              request with credentials, or a request other
              than GET or POST), an OPTIONS preflight
              request is sent to the server to see if the
              action is supported and allowed
            • Successful communication may require a
              CORS-capable server




                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG   Cross-Origin HTTP Headers
            • A cross-origin exchange between a page
              hosted on www.example.com and a service
              hosted on www.example.net (Request):
              POST /main HTTP/1.1
              Host: www.example.net
              User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3)
                 Gecko/20090910 Ubuntu/9.04 (jaunty) Shiretoko/3.5.3
              Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
              Accept-Language: en-us,en;q=0.5
              Accept-Encoding: gzip,deflate
              Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
              Keep-Alive: 300
              Connection: keep-alive
              Referer: http://www.example.com/
              Origin: http://www.example.com
              Pragma: no-cache
              Cache-Control: no-cache
              Content-Length: 0

                    Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Cross-Origin HTTP Headers
            • Cross-origin exchange between a page
              hosted on www.example.com and a service
              hosted on www.example.net (Response):
              HTTP/1.1 201 Created
              Transfer-Encoding: chunked
              Server: Kaazing Gateway
              Date: Mon, 02 Nov 2009 06:55:08 GMT
              Content-Type: text/plain
              Access-Control-Allow-Origin: http://www.example.com
              Access-Control-Allow-Credentials: true




                    Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Cross-Origin XMLHttpRequest
            • Allows you to build web applications that
              use services hosted on different origins
              • For example, a web application that used static
                content from one origin and Ajax services from
                another
            • Allows client-side aggregation (the
              ultimate mashup)




                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Client-Side Aggregation




               Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                               Browser Support
            • Latest versions of
              • Firefox
              • Chrome
              • Safari




                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG   Cross Document Messaging
            • Enables secure cross-origin
              communication across iframes, tabs, and
              windows (using origin security)
            • Defines the PostMessage API as a
              standard way to send messages
            • Provides asynchronous message passing
              between JavaScript contexts




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG    Cross Document Messaging
            • Can be accomplished by direct scripting
              (a script running in one page tries to
              manipulate another document), but
              may not be allowed due to security
              restrictions




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG   PostMessage Overview




              Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG      HTML5 PostMessage
            • Allows you to communicate between
              documents served by different origins
            • Also handy for same-origin messaging,
              because it provides a consistent, easy to use
              API (for example, HTML5 Web Workers)




                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG     HTML5 PostMessage
            • Sending a message:
              myFrame.contentWindow.postMessage
                ('Hello, world',
                'http://www.example.com/');




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                        HTML5 PostMessage
            • Listening for messages:
              window.addEventListener(“message”, messageHandler,
                true);
              function messageHandler(e) {
                  switch(e.origin) {
                    case “friend.example.com”:
                    // process message
                    processMessage(e.data);
                    break;
                  default:
                    // message origin not recognized
                    // ignoring message
                }
              }
                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                                Browser Support
            •   Firefox 3.5 and greater
            •   Safari 4.0 and greater
            •   Chrome 2.0 and greater
            •   Opera 9.6 and greater
            •   Internet Explorer 8 (supports cross-frame
                but not cross-window messaging)




                    Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
             Extending HTML5 WebSockets
            • Once you have a bi-directional, full-
              duplex socket connection, you can do all
              kinds of great things in a browser
            • Any TCP-based protocol works over
              WebSocket
              • JMS, AMQP, STOMP, XMPP, IMAP, AMQP,
                IRC, and more
              • Custom Protocols
            • Binary Protocols
              • Encode Binary as Text

                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                       Stomp Example
            • Streaming Text Oriented Messaging
              Protocol
            • Connect to a message broker to
              publish and subscribe to channels and
              topics
            • Example message brokers that
              support Stomp:
              • RabbitMQ
              • ActiveMQ
              • More
                 Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG           Stomp Protocol
            Stomp commands Server frames
            •   ABORT                             • ERROR
            •   ACK                               • MESSAGE
            •   BEGIN                             • RECEIPT
            •   COMMIT
            •   CONNECT
                                                  Example Stomp frame:
            •   DISCONNECT
                                                       CONNECTn
            •   SEND                                   login: <username>n
            •   SUBSCRIBE                              passcode:<passcode>n
            •   UNSUBSCRIBE                            n
                                                       ^@

                   Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
               Example Stomp Client
            • Stomp Client
              var myStomp = new StompClient();
              myStomp.onopen =
                function(headers) {
                  myStomp.subscribe(“/topic/destination”);
                }
              myStomp.onmessage =
                function(headers, body) { alert(body); }
              myStomp.connect(“ws://www.websocket.org/stomp”);
              myStomp.send(“Hello STOMP!”,
                           “/topic/destination”);




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Kaazing WebSocket Gateway
            • Enterprise Grade WebSocket server
            • Seamlessly and reliably extends any TCP-
              based business messaging protocol to the
              Web with ultra high performance and
              minimal latency
            • Requires no third-party browser plug-in or
              client-side installation
            • Provides emulation for older browsers so
              you can code against the new standards
              today

                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                  Browser Certification
            • Supports native HTML 5
              Communications (when available) as well
              as emulation for current browsers
            • Certified Browser Versions:
              •   Apple Safari 3.0+
              •   Google Chrome 1.0+
              •   Microsoft Internet Explorer 5.5+
              •   Mozilla Firefox 1.5+
              •   Opera 9.5+


                    Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                        Client Libraries
            •   Stomp and the Stomp-JMS Adapter
            •   AMQP
            •   XMPP (Jabber)
            •   IRC
            •   Darkstar
            •   More added all the time




                    Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
            Client Library Technologies
            • JavaScript
            • Adobe Flex (Flash)
            • Microsoft Silverlight (Kaazing is a
              Microsoft Silverlight partner)
            • Java and JavaFX (Kaazing is a Sun
              Microsystems partner)




                  Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
               Financial Applications




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
               Financial Applications




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                      Earth Control Game
            http://apps.facebook.com/earthcontrol




               Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                                Chess Vegas
                http://www.chessvegas.com/




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG
                              Degony Game
                      http://www.degony.com




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG      Important Links
            • Kaazing Website:
              www.kaazing.com
            • Kaazing Technology Network:
              http://tech.kaazing.com/
            • Download Kaazing WebSocket Gateway:
              http://www.kaazing.com/download
            • “When can I use” site:
              http://a.deveria.com/caniuse/
            • Skills Matter:
              www.skillsmatter.com
            • Zenika:
              http://www.zenika.com
                Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG


                         Question 1
                      Win a jQuery book




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            What does “Stomp” stand for?




              Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG


                    Question 2
              Win a jetBrains license




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG




            Which browser supports
             WebSockets natively?




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG

                     Raffle (Tombola)
                     Win an iPod Touch
                      Sponsored by:




            Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG                                   Cocktail

            • Merci pour votre attention
            • Merci au Groupe ADEO pour son
              sponsoring




                 Copyright © Kaazing—License Creative Commons 2.0 France
Ch’ti JUG                                    Licence
            • Les photos et logos appartiennent à leurs
              auteurs respectifs
            • Le contenu de la présentation est sous
              licence Creative Commons 2.0 France
            • Contrat Paternité
            • Pas d'Utilisation Commerciale
            • Partage des Conditions Initiales à
              l'Identique
            • http://creativecommons.org/licenses/by-
              nc-sa/2.0/fr/

                 Copyright © Kaazing—License Creative Commons 2.0 France

More Related Content

PDF
HTML5 WebSockets
PDF
HTML5 WebSocket for the Real-Time Web and the Internet of Things
PDF
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
PDF
Apache HTTPD 2.4 Reverse Proxy: The Hidden Gem
PDF
Past, Present and Future of WebSocket - HTML5DevConf May 2014
PDF
API Design and WebSocket
PDF
WebSocket Perspectives and Vision for the Future - HTML5DevConf Oct 2013 SF
PPTX
HTML5 WebSocket Introduction
HTML5 WebSockets
HTML5 WebSocket for the Real-Time Web and the Internet of Things
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
Apache HTTPD 2.4 Reverse Proxy: The Hidden Gem
Past, Present and Future of WebSocket - HTML5DevConf May 2014
API Design and WebSocket
WebSocket Perspectives and Vision for the Future - HTML5DevConf Oct 2013 SF
HTML5 WebSocket Introduction

What's hot (14)

PDF
WebSocket Perspectives and Vision for the Future
PDF
Apache httpd 2.4 Reverse Proxy: The Hidden Gem
PDF
Real Life WebSocket Case Studies and Demos
PDF
Velocity 2012: The 90-Minute Mobile Optimization Life Cycle
PDF
Apache httpd Reverse Proxy and Tomcat
PDF
Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015
PDF
What's New and Newer in Apache httpd-24
PDF
Apache httpd 2.4 overview
PPTX
WebSocket protocol
PPT
ppt tips
PDF
Not your daddy's web server
PDF
HTTP/2 and a Faster Web
PDF
Velocity 2012 - Taming the Mobile Beast
PDF
Building great mobile apps: Somethings you might want to know
WebSocket Perspectives and Vision for the Future
Apache httpd 2.4 Reverse Proxy: The Hidden Gem
Real Life WebSocket Case Studies and Demos
Velocity 2012: The 90-Minute Mobile Optimization Life Cycle
Apache httpd Reverse Proxy and Tomcat
Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015
What's New and Newer in Apache httpd-24
Apache httpd 2.4 overview
WebSocket protocol
ppt tips
Not your daddy's web server
HTTP/2 and a Faster Web
Velocity 2012 - Taming the Mobile Beast
Building great mobile apps: Somethings you might want to know
Ad

Viewers also liked (8)

PPT
MGD Html5 pres fr
PDF
Mi Iv 200 A Eleve Copy
PPS
Le Vaccin De La Conspiration
PPTX
Révision CHIMIE
PPTX
Oscaro - Conseils mecaniques - émetteur et récepteur
PDF
Adobe flash platform java
PDF
Spring 3.1
PDF
AOSOIT_2017
MGD Html5 pres fr
Mi Iv 200 A Eleve Copy
Le Vaccin De La Conspiration
Révision CHIMIE
Oscaro - Conseils mecaniques - émetteur et récepteur
Adobe flash platform java
Spring 3.1
AOSOIT_2017
Ad

Similar to HTML5 ADEO (20)

PDF
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
PPTX
V2 peter-lubbers-sf-jug-websocket
PPTX
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
KEY
The HTML5 WebSocket API
PDF
Building Living Web Applications with HTML5 WebSockets
PDF
Unit v
PPTX
Writing Portable WebSockets in Java
PPTX
Codecamp Iasi-26 nov 2011 - Html 5 WebSockets
PPT
introduction to Web system
PPT
Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
PPTX
Codecamp iasi-26 nov 2011-web sockets
DOCX
CN 6131(15) Module IV.docx
PDF
CN 6131(15) Module IV.pdf
PPTX
HTML5 Real-Time and Connectivity
PDF
Network concepts
PDF
PDF
HTML5 Websockets and Java - Arun Gupta
PDF
Developing Revolutionary Web Applications using Comet and Ajax Push
PDF
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
PDF
Websocket 1.0
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
V2 peter-lubbers-sf-jug-websocket
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
The HTML5 WebSocket API
Building Living Web Applications with HTML5 WebSockets
Unit v
Writing Portable WebSockets in Java
Codecamp Iasi-26 nov 2011 - Html 5 WebSockets
introduction to Web system
Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
Codecamp iasi-26 nov 2011-web sockets
CN 6131(15) Module IV.docx
CN 6131(15) Module IV.pdf
HTML5 Real-Time and Connectivity
Network concepts
HTML5 Websockets and Java - Arun Gupta
Developing Revolutionary Web Applications using Comet and Ajax Push
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Websocket 1.0

More from Ch'ti JUG (8)

PDF
Java 8 : Un ch'ti peu de lambda
PPTX
Bonita Open Solution
PDF
MC3SI Chti Jug Soiree Agilite
PDF
Chti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projets
PDF
GlassFish ESB Ch'ti JUG
PDF
Drools Planner Chtijug 2010
PDF
Lille2010markp
ODP
Terracotta Ch'ti Jug
Java 8 : Un ch'ti peu de lambda
Bonita Open Solution
MC3SI Chti Jug Soiree Agilite
Chti Jug Octo 16032010 Réduisons le ticket d’entrée de nos projets
GlassFish ESB Ch'ti JUG
Drools Planner Chtijug 2010
Lille2010markp
Terracotta Ch'ti Jug

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Empathic Computing: Creating Shared Understanding
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
Teaching material agriculture food technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Cloud computing and distributed systems.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
KodekX | Application Modernization Development
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Empathic Computing: Creating Shared Understanding
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Cloud computing and distributed systems.
“AI and Expert System Decision Support & Business Intelligence Systems”
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...

HTML5 ADEO

  • 1. Ch’ti JUG HTML5 Communication Building Real-Time Applications with HTML5 Web Sockets Ch'ti Java User Group http://chtijug.org/ Peter Lubbers, Kaazing 10 December 2009 Copyright © Kaazing—License Creative Commons 2.0 France
  • 3. Ch’ti JUG Qui C’est Ce Mec? Peter Lubbers • Director of documentation and training at Kaazing • Skills Matter and Zenika HTML5 training courses • Co-author Apress Book Pro HTML5 Programming (Spring 2010) • Ultramarathon runner, blogger runlaketahoe.blogspot.com Copyright © Kaazing—License Creative Commons 2.0 France
  • 4. Ch’ti JUG Agenda • Introduction • History of the real-time Web • WebSocket and Server-Sent Events • Cross-Document Messaging and XHR Level 2 • Beyond WebSocket • Questions? Copyright © Kaazing—License Creative Commons 2.0 France
  • 5. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 6. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 7. Ch’ti JUG Today’s Requirements • Today’s Web applications demand reliable, real-time communications with near-zero latency • Examples: • Financial applications • Social networking applications • Online games • Smart power grid Copyright © Kaazing—License Creative Commons 2.0 France
  • 8. Ch’ti JUG HTTP Limitations • Until now, this has been cumbersome to achieve, primarily due to the limitations of HTTP • HTTP is half-duplex (traffic flows in only one direction at a time) • HTTP is a stateless, request-driven protocol Copyright © Kaazing—License Creative Commons 2.0 France
  • 9. Ch’ti JUG HTTP Limitations • Header information is sent with each HTTP request and response, which can be an unnecessary overhead • After a response is sent, the server may choose to close the socket • Rich Internet Applications (with Ajax, Comet, Silverlight, and Flash) are becoming richer, but still limited by HTTP Copyright © Kaazing—License Creative Commons 2.0 France
  • 10. Ch’ti JUG Ajax and Comet • Ajax (Asynchronous JavaScript and XML) is a technique for building highly interactive applications for the Web • Content can change without loading the entire page • Ajax Delivers: • User-perceived low latency • Single page • “Real-time” often achieved through polling and long-polling (Comet) Copyright © Kaazing—License Creative Commons 2.0 France
  • 11. Ch’ti JUG Polling • Polling is “nearly real-time” • Sometimes used in Ajax applications to simulate real-time communication • Browser sends HTTP requests at regular intervals and immediately receives a response Copyright © Kaazing—License Creative Commons 2.0 France
  • 12. Ch’ti JUG Polling Architecture Copyright © Kaazing—License Creative Commons 2.0 France
  • 13. Ch’ti JUG Long Polling • Also known as asynchronous-polling • Browser sends a request to the server and the server keeps the request open for a set period. • HTTP headers, present in both long- polling and polling often account for more than half of the network traffic. Copyright © Kaazing—License Creative Commons 2.0 France
  • 14. Ch’ti JUG Long Polling Architecture Copyright © Kaazing—License Creative Commons 2.0 France
  • 15. Ch’ti JUG Streaming • More Efficient, but still not perfect • Possible complications: • Proxies and Firewalls • Response builds up and must be flushed periodically • Cross-domain issues to do with browser connection limits Copyright © Kaazing—License Creative Commons 2.0 France
  • 16. Ch’ti JUG Half-Duplex Architecture Copyright © Kaazing—License Creative Commons 2.0 France
  • 17. Ch’ti JUG Streaming Architecture Copyright © Kaazing—License Creative Commons 2.0 France
  • 18. Ch’ti JUG Current Approaches Are… Fake Time! Or: Not Really Time Copyright © Kaazing—License Creative Commons 2.0 France
  • 19. Ch’ti JUG Example of Polling in Action Copyright © Kaazing—License Creative Commons 2.0 France
  • 20. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 21. Ch’ti JUG HTTP Header Overhead Copyright © Kaazing—License Creative Commons 2.0 France
  • 22. Ch’ti JUG Example HTTP Request GET /PollingStock//PollingStock HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*; q=0.8 Accept-Language: en-us Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/PollingStock/ Cookie: showInheritedConstant=false; showInheritedProtectedConstant=false; showInheritedProperty=false; showInheritedProtectedProperty=false; showInheritedMethod=false; showInheritedProtectedMethod=false; showInheritedEvent=false; showInheritedStyle=false; showInheritedEffect=false Copyright © Kaazing—License Creative Commons 2.0 France
  • 23. Ch’ti JUG Example HTTP Response HTTP/1.x 200 OK X-Powered-By: Servlet/2.5 Server: Sun Java System Application Server 9.1_02 Content-Type: text/html;charset=UTF-8 Content-Length: 321 Date: Sat, 07 Nov 2009 00:32:46 GMT Copyright © Kaazing—License Creative Commons 2.0 France
  • 24. Ch’ti JUG HTTP Header Traffic Analysis • Example network throughput for Polling HTTP request and response headers: • Use case A: 10,000 clients polling every 60 seconds: • Network throughput is (871 x 10,000)/60 = 145,166 bytes = 1,161,328 bits per second (1.1 Mbps) • Use case B: 10,000 clients polling every second: • Network throughput is (871 x 10,000) = 8,710,000 bytes = 69,680,000 bits per second (66 Mbps) • Use case C: 100,000 clients polling every 10 seconds: • Network throughput is (871 x 100,000)/10 = 8710000 bytes = 69,680,000 bits per second (66 Mbps) Copyright © Kaazing—License Creative Commons 2.0 France
  • 25. Ch’ti JUG Network Throughput Comparison Copyright © Kaazing—License Creative Commons 2.0 France
  • 26. Ch’ti JUG Technology-Specific Problems • AJAX • Enables clients to asynchronously poll for server-side events (at best) • Polling leads to poor resource utilization on both the client and server • Comet • Lack of a standard implementation • Often requires complex techniques such as multiplexing or managing multiple domains Copyright © Kaazing—License Creative Commons 2.0 France
  • 27. Ch’ti JUG Headache 2.0 Copyright © Kaazing—License Creative Commons 2.0 France
  • 28. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 29. Ch’ti JUG Desktop vs. Browser • Desktop Networking • Full-duplex bidirectional TCP sockets • Access any server on the network • Browser Networking • Half-duplex HTTP request-response • HTTP polling, long polling fraught with problems Copyright © Kaazing—License Creative Commons 2.0 France
  • 30. Ch’ti JUG Desktop Architecture Copyright © Kaazing—License Creative Commons 2.0 France
  • 31. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 32. Ch’ti JUG About HTML5 • HTML5 is the next set of W3C HTML standards • It offers new and enhanced features to address new HTML primitives, multimedia, offline use, communication, and so on • Many of the browser vendors have already implemented several of these features Copyright © Kaazing—License Creative Commons 2.0 France
  • 33. Ch’ti JUG HTML5 Features • HTML5 includes a wide range of new features, including: • Canvas • Workers • Geolocation • New form elements • Offline storage • Communication APIs • And more… Copyright © Kaazing—License Creative Commons 2.0 France
  • 34. Ch’ti JUG HTML5 Communication • WebSocket • Proxy/Firewall-friendly text socket for browsers • Server-Sent Events • Standardized HTTP streaming (downstream) • XMLHttpRequest Level 2 • Cross-origin XMLHttpRequest • Cross Document Messaging • Secure inter-window (iframe) communication Copyright © Kaazing—License Creative Commons 2.0 France
  • 35. Ch’ti JUG Part of the HTML5 Spec? • Web Sockets—like other pieces of the HTML5 effort such as Local Storage and Geolocation—was originally part of the HTML5 specification • Moved to a separate standards document to keep the specification focused • Web Sockets has been submitted to the Internet Engineering Task Force (IETF) by its creators, the WHATWG Copyright © Kaazing—License Creative Commons 2.0 France
  • 36. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 37. Ch’ti JUG HTML5 WebSockets • HTTP-friendly TCP for the browser with minimal framing • Full-duplex bidirectional communication • Operates over a single socket • Distributed client-server architecture • No browser plug-ins • Traverses proxies and firewalls seamlessly • Allows authorized cross-origin communication Copyright © Kaazing—License Creative Commons 2.0 France
  • 38. Ch’ti JUG WebSocket Architecture Copyright © Kaazing—License Creative Commons 2.0 France
  • 39. Ch’ti JUG HTML5 WebSockets • Connection established by upgrading from the HTTP protocol to the WebSocket protocol using the same TCP connection • WebSocket data frames can be sent back and forth between the client and the server in full-duplex mode Copyright © Kaazing—License Creative Commons 2.0 France
  • 40. Ch’ti JUG HTML5 WebSocket Schemes • WebSocket ws://www.websocket.org/text • WebSocket Secure wss://www.websocket.org/encrypted-text Copyright © Kaazing—License Creative Commons 2.0 France
  • 41. Ch’ti JUG HTML5 WebSocket Handshake GET /text HTTP/1.1rn Upgrade: WebSocketrn Connection: Upgradern Host: www.websocket.orgrn …rn HTTP/1.1 101 WebSocket Protocol Handshakern Upgrade: WebSocketrn Connection: Upgradern …rn Copyright © Kaazing—License Creative Commons 2.0 France
  • 42. Ch’ti JUG HTML5 WebSocket Frames • Text and binary frames can be sent full-duplex, in either direction at any the same time • Each frame of data: • Starts with a 0x00 byte • Ends with a 0xFF byte • Contains UTF-8 data in between • Text Frames use terminator • x00Hello, WebSocket0xff • Binary Frames use length prefix: • x000x10Hello, WebSocket • There is no defined maximum size • If the user agent has content that is too large to be handled, it must fail the Web Socket connection • JavaScript does not allow >4GB of data, so that is a practical maximum Copyright © Kaazing—License Creative Commons 2.0 France
  • 43. Ch’ti JUG Drastic Reduction in Network Traffic • With WebSocket, each frame has only 2 bytes of packaging (compare almost 500:1 or even 1000:1) • No latency involved in establishing new TCP connections for each HTTP message • Remember the Polling HTTP header traffic (66 Mbps network throughput for headers alone)? Copyright © Kaazing—License Creative Commons 2.0 France
  • 44. Ch’ti JUG HTTP Header Traffic Analysis • Example network throughput for WebSocket HTTP request and response headers: • Use case A: 10,000 frames every 60 seconds: • Network throughput is (2 x 10,000)/60 = 333 bytes = 2,664 bits per second (2.6 Kbps) • Use case B: 10,000 frames every second: • Network throughput is (2 x 10,000) = 20,000 bytes = 160,000 bits per second (156 Kbps) • Use case C: 100,000 frames every 10 seconds: • Network throughput is (2 x 100,000)/10 = 20,000 bytes = 160,000 bits per second (156 Kbps) Copyright © Kaazing—License Creative Commons 2.0 France
  • 45. Ch’ti JUG Network Throughput Comparison Copyright © Kaazing—License Creative Commons 2.0 France
  • 46. Ch’ti JUG Overheard… "Reducing kilobytes of data to 2 bytes…and reducing latency from 150ms to 50ms is far more than marginal. In fact, these two factors alone are enough to make WebSocket seriously interesting to Google.“ —Ian Hickson (Google, HTML5 spec lead) Copyright © Kaazing—License Creative Commons 2.0 France
  • 47. Ch’ti JUG HTML5 WebSockets API • Creating a WebSocket instance: var myWebSocket = new WebSocket (“ws://www.websocket.org”); Copyright © Kaazing—License Creative Commons 2.0 France
  • 48. Ch’ti JUG HTML5 WebSockets API • Associating listeners myWebSocket.onopen = function(evt) { alert(“Connection open ...”); }; myWebSocket.onmessage = function(evt) { alert( “Received Message: ” + evt.data); }; myWebSocket.onclose = function(evt) { alert(“Connection closed.”); }; Copyright © Kaazing—License Creative Commons 2.0 France
  • 49. Ch’ti JUG HTML5 WebSockets API • Sending messages myWebSocket.send(“Hello WebSocket!”); myWebSocket.close(); Copyright © Kaazing—License Creative Commons 2.0 France
  • 50. Ch’ti JUG Browser Support • Chromium support added just a few weeks ago (nightly builds) • Webkit activity Copyright © Kaazing—License Creative Commons 2.0 France
  • 51. Ch’ti JUG Native WebSocket in Chromium : Copyright © Kaazing—License Creative Commons 2.0 France
  • 52. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 53. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 54. Ch’ti JUG HTML5 Server-Sent Events • Standardizes and formalizes how a continuous stream of data can be sent from a server to a browser • Introduces EventSource—a new JavaScript API Copyright © Kaazing—License Creative Commons 2.0 France
  • 55. Ch’ti JUG SSE Architecture Copyright © Kaazing—License Creative Commons 2.0 France
  • 56. Ch’ti JUG EventSource API • Connects to a server URL to receive an event stream: var stream = new EventSource("http://news.kaazing.com"); • Set event handlers: stream.onopen = function() { alert(“open”); } stream.onmessage = function(event) { alert(“message: “ + event.data); } stream.onerror = function() { alert(“error”); } Copyright © Kaazing—License Creative Commons 2.0 France
  • 57. Ch’ti JUG Browser Support • Partial support in Opera 9+ • Development in Firefox trunk Copyright © Kaazing—License Creative Commons 2.0 France
  • 58. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 59. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 60. Ch’ti JUG XMLHttpRequest Level 2 • XMLHttpRequest is the API that made Ajax possible • XMLHttpRequest Level 2 significantly enhances XMLHttpRequest • Improvements in the following areas: • Progress events • Cross-origin XMLHttpRequests Copyright © Kaazing—License Creative Commons 2.0 France
  • 61. Ch’ti JUG Progress Events • XMLHttpRequest Level 2 supports named progress events: • loadstart • progress • abort • error • load • loadend • readyState property and readystatechange events retained for backward compatibility Copyright © Kaazing—License Creative Commons 2.0 France
  • 62. Ch’ti JUG Progress Events • Progress events have fields for: • The total amount of data to transfer • The amount that has already transferred • Whether the total is known (Boolean value) • Example: crossOriginRequest.upload.onprogress = function(e) { var total = e.total; var loaded = e.loaded; if (e.lengthComputable) { // do something with the progress information } } Copyright © Kaazing—License Creative Commons 2.0 France
  • 63. Ch’ti JUG Cross-Origin XMLHttpRequest • XMLHttpRequest Level 2 allows for cross- origin XMLHttpRequests using Cross Origin Resource Sharing (CORS) http://www.w3.org/TR/access- control/ • Example: var crossOriginRequest = new XMLHttpRequest(); crossOriginRequest.open("GET", "http://www.example.net/stockfeed", true); Copyright © Kaazing—License Creative Commons 2.0 France
  • 64. Ch’ti JUG Origin Security • An origin is a subset of an address used for modeling trust relationships on the Web • Origins are made up of a scheme, a host, and a port—different origin: • https://www.example.com • http://www.example.com • The path is not considered in the origin value—same origin: • http://www.example.com/index.html • http://www.example.com/page2.html Copyright © Kaazing—License Creative Commons 2.0 France
  • 65. Ch’ti JUG Origin Security • Cross-origin communication identifies the sender by origin • Allows receiver to ignore messages from origins it does not trust or does not expect to receive messages from (white list) • Applications must opt-in to receiving messages by adding an event listener for message events • No risk of messages interfering with an unsuspecting application Copyright © Kaazing—License Creative Commons 2.0 France
  • 66. Ch’ti JUG Preflight Requests • For sensitive actions (for example, a request with credentials, or a request other than GET or POST), an OPTIONS preflight request is sent to the server to see if the action is supported and allowed • Successful communication may require a CORS-capable server Copyright © Kaazing—License Creative Commons 2.0 France
  • 67. Ch’ti JUG Cross-Origin HTTP Headers • A cross-origin exchange between a page hosted on www.example.com and a service hosted on www.example.net (Request): POST /main HTTP/1.1 Host: www.example.net User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090910 Ubuntu/9.04 (jaunty) Shiretoko/3.5.3 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://www.example.com/ Origin: http://www.example.com Pragma: no-cache Cache-Control: no-cache Content-Length: 0 Copyright © Kaazing—License Creative Commons 2.0 France
  • 68. Ch’ti JUG Cross-Origin HTTP Headers • Cross-origin exchange between a page hosted on www.example.com and a service hosted on www.example.net (Response): HTTP/1.1 201 Created Transfer-Encoding: chunked Server: Kaazing Gateway Date: Mon, 02 Nov 2009 06:55:08 GMT Content-Type: text/plain Access-Control-Allow-Origin: http://www.example.com Access-Control-Allow-Credentials: true Copyright © Kaazing—License Creative Commons 2.0 France
  • 69. Ch’ti JUG Cross-Origin XMLHttpRequest • Allows you to build web applications that use services hosted on different origins • For example, a web application that used static content from one origin and Ajax services from another • Allows client-side aggregation (the ultimate mashup) Copyright © Kaazing—License Creative Commons 2.0 France
  • 70. Ch’ti JUG Client-Side Aggregation Copyright © Kaazing—License Creative Commons 2.0 France
  • 71. Ch’ti JUG Browser Support • Latest versions of • Firefox • Chrome • Safari Copyright © Kaazing—License Creative Commons 2.0 France
  • 72. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 73. Ch’ti JUG Cross Document Messaging • Enables secure cross-origin communication across iframes, tabs, and windows (using origin security) • Defines the PostMessage API as a standard way to send messages • Provides asynchronous message passing between JavaScript contexts Copyright © Kaazing—License Creative Commons 2.0 France
  • 74. Ch’ti JUG Cross Document Messaging • Can be accomplished by direct scripting (a script running in one page tries to manipulate another document), but may not be allowed due to security restrictions Copyright © Kaazing—License Creative Commons 2.0 France
  • 75. Ch’ti JUG PostMessage Overview Copyright © Kaazing—License Creative Commons 2.0 France
  • 76. Ch’ti JUG HTML5 PostMessage • Allows you to communicate between documents served by different origins • Also handy for same-origin messaging, because it provides a consistent, easy to use API (for example, HTML5 Web Workers) Copyright © Kaazing—License Creative Commons 2.0 France
  • 77. Ch’ti JUG HTML5 PostMessage • Sending a message: myFrame.contentWindow.postMessage ('Hello, world', 'http://www.example.com/'); Copyright © Kaazing—License Creative Commons 2.0 France
  • 78. Ch’ti JUG HTML5 PostMessage • Listening for messages: window.addEventListener(“message”, messageHandler, true); function messageHandler(e) { switch(e.origin) { case “friend.example.com”: // process message processMessage(e.data); break; default: // message origin not recognized // ignoring message } } Copyright © Kaazing—License Creative Commons 2.0 France
  • 79. Ch’ti JUG Browser Support • Firefox 3.5 and greater • Safari 4.0 and greater • Chrome 2.0 and greater • Opera 9.6 and greater • Internet Explorer 8 (supports cross-frame but not cross-window messaging) Copyright © Kaazing—License Creative Commons 2.0 France
  • 80. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 81. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 82. Ch’ti JUG Extending HTML5 WebSockets • Once you have a bi-directional, full- duplex socket connection, you can do all kinds of great things in a browser • Any TCP-based protocol works over WebSocket • JMS, AMQP, STOMP, XMPP, IMAP, AMQP, IRC, and more • Custom Protocols • Binary Protocols • Encode Binary as Text Copyright © Kaazing—License Creative Commons 2.0 France
  • 83. Ch’ti JUG Stomp Example • Streaming Text Oriented Messaging Protocol • Connect to a message broker to publish and subscribe to channels and topics • Example message brokers that support Stomp: • RabbitMQ • ActiveMQ • More Copyright © Kaazing—License Creative Commons 2.0 France
  • 84. Ch’ti JUG Stomp Protocol Stomp commands Server frames • ABORT • ERROR • ACK • MESSAGE • BEGIN • RECEIPT • COMMIT • CONNECT Example Stomp frame: • DISCONNECT CONNECTn • SEND login: <username>n • SUBSCRIBE passcode:<passcode>n • UNSUBSCRIBE n ^@ Copyright © Kaazing—License Creative Commons 2.0 France
  • 85. Ch’ti JUG Example Stomp Client • Stomp Client var myStomp = new StompClient(); myStomp.onopen = function(headers) { myStomp.subscribe(“/topic/destination”); } myStomp.onmessage = function(headers, body) { alert(body); } myStomp.connect(“ws://www.websocket.org/stomp”); myStomp.send(“Hello STOMP!”, “/topic/destination”); Copyright © Kaazing—License Creative Commons 2.0 France
  • 86. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 87. Ch’ti JUG Kaazing WebSocket Gateway • Enterprise Grade WebSocket server • Seamlessly and reliably extends any TCP- based business messaging protocol to the Web with ultra high performance and minimal latency • Requires no third-party browser plug-in or client-side installation • Provides emulation for older browsers so you can code against the new standards today Copyright © Kaazing—License Creative Commons 2.0 France
  • 88. Ch’ti JUG Browser Certification • Supports native HTML 5 Communications (when available) as well as emulation for current browsers • Certified Browser Versions: • Apple Safari 3.0+ • Google Chrome 1.0+ • Microsoft Internet Explorer 5.5+ • Mozilla Firefox 1.5+ • Opera 9.5+ Copyright © Kaazing—License Creative Commons 2.0 France
  • 89. Ch’ti JUG Client Libraries • Stomp and the Stomp-JMS Adapter • AMQP • XMPP (Jabber) • IRC • Darkstar • More added all the time Copyright © Kaazing—License Creative Commons 2.0 France
  • 90. Ch’ti JUG Client Library Technologies • JavaScript • Adobe Flex (Flash) • Microsoft Silverlight (Kaazing is a Microsoft Silverlight partner) • Java and JavaFX (Kaazing is a Sun Microsystems partner) Copyright © Kaazing—License Creative Commons 2.0 France
  • 91. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 92. Ch’ti JUG Financial Applications Copyright © Kaazing—License Creative Commons 2.0 France
  • 93. Ch’ti JUG Financial Applications Copyright © Kaazing—License Creative Commons 2.0 France
  • 94. Ch’ti JUG Earth Control Game http://apps.facebook.com/earthcontrol Copyright © Kaazing—License Creative Commons 2.0 France
  • 95. Ch’ti JUG Chess Vegas http://www.chessvegas.com/ Copyright © Kaazing—License Creative Commons 2.0 France
  • 96. Ch’ti JUG Degony Game http://www.degony.com Copyright © Kaazing—License Creative Commons 2.0 France
  • 97. Ch’ti JUG Important Links • Kaazing Website: www.kaazing.com • Kaazing Technology Network: http://tech.kaazing.com/ • Download Kaazing WebSocket Gateway: http://www.kaazing.com/download • “When can I use” site: http://a.deveria.com/caniuse/ • Skills Matter: www.skillsmatter.com • Zenika: http://www.zenika.com Copyright © Kaazing—License Creative Commons 2.0 France
  • 98. Ch’ti JUG Copyright © Kaazing—License Creative Commons 2.0 France
  • 99. Ch’ti JUG Question 1 Win a jQuery book Copyright © Kaazing—License Creative Commons 2.0 France
  • 100. Ch’ti JUG What does “Stomp” stand for? Copyright © Kaazing—License Creative Commons 2.0 France
  • 101. Ch’ti JUG Question 2 Win a jetBrains license Copyright © Kaazing—License Creative Commons 2.0 France
  • 102. Ch’ti JUG Which browser supports WebSockets natively? Copyright © Kaazing—License Creative Commons 2.0 France
  • 103. Ch’ti JUG Raffle (Tombola) Win an iPod Touch Sponsored by: Copyright © Kaazing—License Creative Commons 2.0 France
  • 104. Ch’ti JUG Cocktail • Merci pour votre attention • Merci au Groupe ADEO pour son sponsoring Copyright © Kaazing—License Creative Commons 2.0 France
  • 105. Ch’ti JUG Licence • Les photos et logos appartiennent à leurs auteurs respectifs • Le contenu de la présentation est sous licence Creative Commons 2.0 France • Contrat Paternité • Pas d'Utilisation Commerciale • Partage des Conditions Initiales à l'Identique • http://creativecommons.org/licenses/by- nc-sa/2.0/fr/ Copyright © Kaazing—License Creative Commons 2.0 France

Editor's Notes

  • #27: Ajax: poor resource utilization, because CPU-cycles and memory are needlessly allocated to prematurely or belatedly detect updates on the serverComet: lack of standard implementationdue the varying levels of support provided by browser vendors for XHR and iFramesEven in long-polling, HTTP Headers in the response outweigh the message being delivered
  • #30: Desktop TCP (good performance)Request-Response (bad performance, poor bandwidth usage)Browser Polling, Long Polling, Streaming (limited real-time, proxy problems)Portals aggregating content at server (poor scalability)Mashupsaggregating at client for improved scalability – security problems
  • #35: WebSocket is text-only
  • #36: Authors, evangelists, and companies involved in the standardization still refer to the original set of features, including Web Sockets, as "HTML5."
  • #42: HTTP used for handshake onlyOperates over a single socketTraverses firewalls and routers seamlesslyAllows authorized cross-site communicationCookie-based authenticationExisting HTTP load balancersNavigates proxies using HTTP CONNECT, same technique as https, but without the encryption