SlideShare a Scribd company logo
1 of 37
HTML5 WebSocket
                                                   Overview
                                                       The Web Communication Revolution


                       Reduced Complexity                                                          Web. Upgraded.

    High Performance                                                      Enterprise Support



                                                                                               Marcelo Jabali
                                                                                           Solutions Architect
                                                                                                    @mjabali
                                                                                                      July, 2012

1                             Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Agenda


       Introduction to HTML5 WebSocket
       WebSocket API
       WebSocket Protocol




2                  Copyright © 2012 Kaazing Corporation. All Rights Reserved.
About Me


                                                         Marcelo Jabali
                                                         Solutions Consultant

                                                         marcelo.jabali@kaazing.com

                                                         marcelojabali.blogspot.com

                                                         mjabali

                                                         linkedin.com/in/jabali


3              Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Architectural (R)evolution

         Legacy Web
                                        Half Duplex                                           Full duplex




                                           Web

                Browser
                                                                             Web        Middleware Back-end
                                                                             Tier                   server

         Living Web

                                            WebSocket                                  Full duplex



                                              Web

                                                                        WebSocket                    Back-end
                                                                         Server                       server


4                         Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Limitations of HTTP


    •   Designed for document transfer
         • Request-response interaction
    •   Bi-directional but still half-duplex
         • Traffic flows in only one direction at a time
    •   Stateless
         • Header overhead
         information is
         sent with each HTTP
         request and response

5                     Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Emulating full-duplex HTTP


     •   AJAX (Asynchronous JavaScript + XML)
         • Content can change without loading the
           entire page
         • User-perceived low latency
     •   Comet
         • Technique for server push
         • Lack of a standard implementation
         • Comet adds lots of complexity


6                   Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Polling


    •   Polling is "nearly real-time"
    •   Used in Ajax applications to simulate real-time
        communication
    •   Browser sends HTTP requests at regular
        intervals and immediately receives a response




7                    Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Long Polling
    a/k/a Asynchronous polling



     •   Browser sends a request to the server, server
         keeps the request open for a set period
     •   Speed limited by response-request-response
     •   Request/response headers add overhead on
         the wire




8                                Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Streaming



    •   More efficient, but sometimes
        problematic
    •   Possible complications:
        o Proxies and firewalls
        o Response builds up and must be flushed
           periodically
        o Cross-domain issues
        to do with browser
        connection limits


9                   Copyright © 2012 Kaazing Corporation. All Rights Reserved.
HTTP Request Headers

     Client


        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;




10                         Copyright © 2012 Kaazing Corporation. All Rights Reserved.
HTTP Response Headers


     Server

        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




          • Total overhead: 871 bytes (example)
          • Often 2K+ bytes
             • e.g. cookies



11                          Copyright © 2012 Kaazing Corporation. All Rights Reserved.
HTTP Header Traffic Analysis




            Client                       Overhead Bytes                          Overhead Mbps

            1,000                                          871,000                       ~6,6*

            10,000                                     8,710,000                           ~66

            100,000                                  87,100,000                           ~665



                     * 871,000 bytes = 6,968,000 bits = ~6.6 Mbps




12                          Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Overhead…



        "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)




13                  Copyright © 2012 Kaazing Corporation. All Rights Reserved.
HTML5 WebSocket Overview




14         Copyright © 2012 Kaazing Corporation. All Rights Reserved.
WebSocket History



        Originally added to HTML5 specification as
         TCPConnection
        Moved to its
         own specification
         later on




15                   Copyright © 2012 Kaazing Corporation. All Rights Reserved.
HTML5 WebSocket


     •   W3C API and IETF Protocol
     •   Leverages Cross-Origin Resource Sharing
          • Enables web pages to communicate with a remote
            host
     •   Shares port with existing HTTP content
     •    Allows unlimited connections per Origin
         • Unlike HTTP which is limited by convention
         • One WebSocket handshake in progress per Origin
     •   Two schemes:
          • ws://
          • wss://

16                      Copyright © 2012 Kaazing Corporation. All Rights Reserved.
USING THE WEBSOCKET API


17           Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Checking for support


     JavaScript

        var status = document.getElementById("support");
        if (window.WebSocket) { // or Modernizr.websocket
          status.innerHTML = "HTML5 WebSocket is supported";
        } else {
          status.innerHTML = "HTML5 WebSocket is not supported";
        }




18                     Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Using the WebSocket API

     JavaScript

        //Create new WebSocket
        var mySocket = new WebSocket("ws://www.WebSocket.org");

        // Associate listeners
        mySocket.onopen = function(evt) {
        };
        mySocket.onclose = function(evt) {
          alert("closed w/ status: " + evt.code};
        };
        mySocket.onmessage = function(evt) {
          alert("Received message: " + evt.data);
        };
        mySocket.onerror = function(evt) {
          alert("Error);
        };



19                     Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Using the WebSocket API



     JavaScript


        // Sending data
        mySocket.send("WebSocket Rocks!");

        // Close WebSocket
        mySocket.close();




20                     Copyright © 2012 Kaazing Corporation. All Rights Reserved.
WebSocket API


     Available? window.WebSocket or
                Modernizr.websocket
     Events     onopen, onerror, onmessage
     Functions send, close
     Attributes url, readyState,
                bufferedAmount, extensions,
                protocol

              http://dev.w3.org/html5/websockets/



                                                                                   Italics: -08 and later
21                    Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Browser Support

     Native:
     • Chrome 4+
     • Safari 5+
     • Firefox 4+
     • Opera 10.7+
     • Internet Explorer 10+




22                 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
WebSocket Servers Libraries

        Kaazing                        •     Misultin                                      Client Libraries
        Socket.io (node.js)            •     Cowboy                                        • Web-socket-js (JavaScript)
        Apache-websocket               •     YAWS                                          • AS3 WebSocket (ActionScript)
        Cramp                          •     Juggernaut                                    • .NET WebSocket client (.NET)
        Nowjs                          •     PHP Websocket                                 • Anaida (.NET)
        SockJS
                                        •     websockify                                    • WebSocket Sharp (.NET)
        SuperWebSocket
                                        •     ActiveMQ                                      • Silverlight WebSocket client
        Jetty
                                        •     HornetMQ                                      • Java WebSocket Client
        Atmosphere
                                        •     phpwebsocket                                  • Arduino C++ WebSocket client
        APE Project
                                        •     Protocol::WebSocket                           • Ruby-web-socket
        Xsockets
        Orbited                        •     em-websocket                                  • ZTWebSocket (Objective-C)
        Atmosphere                     •     Jwebsocket                                    • Libwebsockets (C)
        Autobahn                       •     WaterSprout Server
        CouchDB                        •     Pywebsocket
        Netty                          •     And more…




23                             Copyright © 2012 Kaazing Corporation. All Rights Reserved.
THE WEBSOCKET PROTOCOL


24          Copyright © 2012 Kaazing Corporation. All Rights Reserved.
WebSocket Protocol History
     “draft-hixie-thewebsocketprotocol-xx” IETF Network Working Group
     Version        Date                            Details
     -00            Jan. 9 2009                     • Initial version
     -52            Oct. 23 2009                    • Subprotocol concept introduced
     -76            May 6 2010                      • Used in older browsers (FF4, etc.)

     “draft-ietf-hybi-thewebsocketprotocol-xx” (IETF HyBi Working Group)
     Version       Date                             Details
     -01           Aug. 31 2010                     • Added binary format
     -04           Jan. 11 2011                     • Introduced data masking to address proxy
                                                      server security issue
                                                    • Introduced including protocol version number
                                                      in handshake
     -14           Sep. 8 2011                      • Guidance on version number negotiation
     RFC 6455      Dec. 2011                        • Final version
                                                       http://tools.ietf.org/html/rfc6455

25                          Copyright © 2012 Kaazing Corporation. All Rights Reserved.
WebSocket Handshake




26                 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
WebSocket Frames


      •   Have a few header bytes
      •   Text or binary data
      •   Frames are masked from client to server




27                  Copyright © 2012 Kaazing Corporation. All Rights Reserved.
WebSocket Frames
     Wireshark Trace of WebSocket Message (Client to Server)




                                         FIN bit, MASK bit,
                                       RSV bits, Op- payload                mask             payload
                                          Code        length

                                             81 85 CB 6E 9F 8E 83 0B F3 E2 A4

                                                                                     83 0B F3 E2 A4
                                                                                   XOR CB 6E 9F 8E CB
                                                                                     -- -- -- -- --
                                                                                     48 65 6C 6C 6F
                                                                                      H e l l o


28                           Copyright © 2012 Kaazing Corporation. All Rights Reserved.
WebSocket Efficiency


                      HTTP                                             WebSocket
     Overhead         100s of bytes                                    2-6 bytes (typical)
     Latency          New connection                                   None: Use existing
                      each time                                        connection
     Latency          Wait for next                                    No waiting
     (polling)        interval
     Latency          None, if request                                 No waiting
     (long polling)   sent earlier
                      + time to set up
                      next request

29                     Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Polling vs. WebSocket




30                   Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Latency Reduction




31                   Copyright © 2012 Kaazing Corporation. All Rights Reserved.
WebSocket Benchmark


           Using Comet                                               Using WebSocket




             http://webtide.intalio.com/2011/09/cometd-2-4-0-websocket-benchmarks/

32                     Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Why WebSocket? WebSocket is about…

        Performance
          • WebSocket makes real-time communication much more efficient.

        Simplicity
          • WebSocket makes communication between a client and server
            over the web much simpler.

        Standards
          • WebSocket is an underlying network protocol that enables you to
            build other standard protocols on top of it.

        HTML5
          • WebSocket is part of an effort to provide advanced capabilities to
            HTML5 applications in order to compete with other platforms.


33                         Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Demo – Mobile Notifications
                                                                                                                  Notification Demo Examples
                                                                                                                     1. Gate Change Announcement
                                                                                                                     2. Flight Cancellation
                                                                                                                     3. Refund Request Process
                                                 APNS
                   Push
                Notification                                            TCP/HTTP

                                     Cloud to
                                     Device
                                       Msg




                                                                 F
                                                                          Notifications               ERP                       Refund                      CRM
                                                                 I
                                                                            Engine                                              System
                                                                R
                                                                E
                               HTML5 WebSocket                  W
                                                                AL
      iOS/Android Native or
                                                                 L
        HTML5 Hybrid App                                                                         Enterprise Messaging System / Apache ActiveMQ




                                  HTML5 WebSocket

                                                                                                              Flight Control                   Finance
                                                                                                                 System




                                                                                                                       Legend

                                                                                                                                         Background / Unidirectional
                                                                                                                                         Foreground / Bi-directional,
                                                                                                                                         Low Latency, Guaranteed
                                                                                                                                         Delivery

34                                                      Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Q&A




35   Copyright © 2012 Kaazing Corporation. All Rights Reserved.
36   Copyright © 2012 Kaazing Corporation. All Rights Reserved.
Copyright © 2011 Kaazing Corporation, All rights reserved.
     All materials, including labs and other handouts are property of Kaazing Corporation. Except when expressly
        permitted by Kaazing Corporation, you may not copy, reproduce, publish, or display any part of this training
                                           material, in any form, or by any means.




37                               Copyright © 2012 Kaazing Corporation. All Rights Reserved.

More Related Content

What's hot

Network emulator
Network emulatorNetwork emulator
Network emulatorjeromy fu
 
WebRTC Overview
WebRTC OverviewWebRTC Overview
WebRTC OverviewArin Sime
 
MQTT
MQTTMQTT
MQTTESUG
 
Introduccion a RPKI - Certificacion de Recursos de Internet
Introduccion a RPKI - Certificacion de Recursos de InternetIntroduccion a RPKI - Certificacion de Recursos de Internet
Introduccion a RPKI - Certificacion de Recursos de InternetCarlos Martinez Cagnazzo
 
Introduction to WebRTC
Introduction to WebRTCIntroduction to WebRTC
Introduction to WebRTCArt Matsak
 
Janus: an open source and general purpose WebRTC (gateway) server
Janus: an open source and general purpose WebRTC (gateway) serverJanus: an open source and general purpose WebRTC (gateway) server
Janus: an open source and general purpose WebRTC (gateway) serverDevDay
 
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)Peter Lubbers
 
Reactive Microsystems: The Evolution of Microservices at Scale
Reactive Microsystems: The Evolution of Microservices at ScaleReactive Microsystems: The Evolution of Microservices at Scale
Reactive Microsystems: The Evolution of Microservices at ScaleJonas Bonér
 
Web 3.0 & IoT (English)
Web 3.0 & IoT (English)Web 3.0 & IoT (English)
Web 3.0 & IoT (English)Peter Waher
 
[오픈소스컨설팅]스카우터엑스 소개
[오픈소스컨설팅]스카우터엑스 소개[오픈소스컨설팅]스카우터엑스 소개
[오픈소스컨설팅]스카우터엑스 소개Open Source Consulting
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response StructureBhagyashreeGajera1
 
The constrained application protocol (CoAP)
The constrained application protocol (CoAP)The constrained application protocol (CoAP)
The constrained application protocol (CoAP)Hamdamboy (함담보이)
 
RPC에서 REST까지 간단한 개념소개
RPC에서 REST까지 간단한 개념소개RPC에서 REST까지 간단한 개념소개
RPC에서 REST까지 간단한 개념소개Wonchang Song
 

What's hot (20)

Amqp Basic
Amqp BasicAmqp Basic
Amqp Basic
 
Network emulator
Network emulatorNetwork emulator
Network emulator
 
WebRTC
WebRTCWebRTC
WebRTC
 
WebRTC Overview
WebRTC OverviewWebRTC Overview
WebRTC Overview
 
MQTT
MQTTMQTT
MQTT
 
Introduccion a RPKI - Certificacion de Recursos de Internet
Introduccion a RPKI - Certificacion de Recursos de InternetIntroduccion a RPKI - Certificacion de Recursos de Internet
Introduccion a RPKI - Certificacion de Recursos de Internet
 
Introduction to WebRTC
Introduction to WebRTCIntroduction to WebRTC
Introduction to WebRTC
 
Janus: an open source and general purpose WebRTC (gateway) server
Janus: an open source and general purpose WebRTC (gateway) serverJanus: an open source and general purpose WebRTC (gateway) server
Janus: an open source and general purpose WebRTC (gateway) server
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
MQTT
MQTTMQTT
MQTT
 
Reactive Microsystems: The Evolution of Microservices at Scale
Reactive Microsystems: The Evolution of Microservices at ScaleReactive Microsystems: The Evolution of Microservices at Scale
Reactive Microsystems: The Evolution of Microservices at Scale
 
Web 3.0 & IoT (English)
Web 3.0 & IoT (English)Web 3.0 & IoT (English)
Web 3.0 & IoT (English)
 
[오픈소스컨설팅]스카우터엑스 소개
[오픈소스컨설팅]스카우터엑스 소개[오픈소스컨설팅]스카우터엑스 소개
[오픈소스컨설팅]스카우터엑스 소개
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure
 
The constrained application protocol (CoAP)
The constrained application protocol (CoAP)The constrained application protocol (CoAP)
The constrained application protocol (CoAP)
 
RPC에서 REST까지 간단한 개념소개
RPC에서 REST까지 간단한 개념소개RPC에서 REST까지 간단한 개념소개
RPC에서 REST까지 간단한 개념소개
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
HTTP/3 for everyone
HTTP/3 for everyoneHTTP/3 for everyone
HTTP/3 for everyone
 

Similar to HTML5 WebSocket Introduction

Building Living Web Applications with HTML5 WebSockets
Building Living Web Applications with HTML5 WebSocketsBuilding Living Web Applications with HTML5 WebSockets
Building Living Web Applications with HTML5 WebSocketsPeter Moskovits
 
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012Arun Gupta
 
HTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaHTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaJAX London
 
Programming WebSockets with Glassfish and Grizzly
Programming WebSockets with Glassfish and GrizzlyProgramming WebSockets with Glassfish and Grizzly
Programming WebSockets with Glassfish and GrizzlyC2B2 Consulting
 
Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
Camelone-2012 HTML5 WebSocket ActiveMQ/CamelCamelone-2012 HTML5 WebSocket ActiveMQ/Camel
Camelone-2012 HTML5 WebSocket ActiveMQ/CamelCharles Moulliard
 
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011Peter Moskovits
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityPeter Lubbers
 
WebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the FutureWebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the FutureFrank Greco
 
Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Peter Lubbers
 
How Scala, Wicket, and Java EE Can Improve Web Development
How Scala, Wicket, and Java EE Can Improve Web DevelopmentHow Scala, Wicket, and Java EE Can Improve Web Development
How Scala, Wicket, and Java EE Can Improve Web DevelopmentBruno Borges
 
HTML5 Overview (Silicon Valley User Group)
HTML5 Overview (Silicon Valley User Group)HTML5 Overview (Silicon Valley User Group)
HTML5 Overview (Silicon Valley User Group)robinzimmermann
 
[English version] JavaFX and Web Integration
[English version] JavaFX and Web Integration[English version] JavaFX and Web Integration
[English version] JavaFX and Web IntegrationKazuchika Sekiya
 
WebBee rapid web app development teck stack
WebBee rapid web app development teck stackWebBee rapid web app development teck stack
WebBee rapid web app development teck stackALDAN3
 
WHAT IS HTML5? (at CSS Nite Osaka)
WHAT IS HTML5? (at CSS Nite Osaka)WHAT IS HTML5? (at CSS Nite Osaka)
WHAT IS HTML5? (at CSS Nite Osaka)Shumpei Shiraishi
 
Consuming Java EE in Desktop, Web, and Mobile Frontends
Consuming Java EE in Desktop, Web, and Mobile FrontendsConsuming Java EE in Desktop, Web, and Mobile Frontends
Consuming Java EE in Desktop, Web, and Mobile FrontendsGeertjan Wielenga
 

Similar to HTML5 WebSocket Introduction (20)

Building Living Web Applications with HTML5 WebSockets
Building Living Web Applications with HTML5 WebSocketsBuilding Living Web Applications with HTML5 WebSockets
Building Living Web Applications with HTML5 WebSockets
 
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
 
HTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaHTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun Gupta
 
Websocket 1.0
Websocket 1.0Websocket 1.0
Websocket 1.0
 
Programming WebSockets with Glassfish and Grizzly
Programming WebSockets with Glassfish and GrizzlyProgramming WebSockets with Glassfish and Grizzly
Programming WebSockets with Glassfish and Grizzly
 
Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
Camelone-2012 HTML5 WebSocket ActiveMQ/CamelCamelone-2012 HTML5 WebSocket ActiveMQ/Camel
Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
 
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
Extending JMS to Web Devices over HTML5 WebSockets - JavaOne 2011
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
 
WebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the FutureWebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the Future
 
Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)Getting Started with HTML5 in Tech Com (STC 2012)
Getting Started with HTML5 in Tech Com (STC 2012)
 
How Scala, Wicket, and Java EE Can Improve Web Development
How Scala, Wicket, and Java EE Can Improve Web DevelopmentHow Scala, Wicket, and Java EE Can Improve Web Development
How Scala, Wicket, and Java EE Can Improve Web Development
 
HTML5 Overview (Silicon Valley User Group)
HTML5 Overview (Silicon Valley User Group)HTML5 Overview (Silicon Valley User Group)
HTML5 Overview (Silicon Valley User Group)
 
Jax2010 adobe lcds
Jax2010 adobe lcdsJax2010 adobe lcds
Jax2010 adobe lcds
 
WebSocket protocol
WebSocket protocolWebSocket protocol
WebSocket protocol
 
Asif
AsifAsif
Asif
 
[English version] JavaFX and Web Integration
[English version] JavaFX and Web Integration[English version] JavaFX and Web Integration
[English version] JavaFX and Web Integration
 
WebBee rapid web app development teck stack
WebBee rapid web app development teck stackWebBee rapid web app development teck stack
WebBee rapid web app development teck stack
 
WHAT IS HTML5? (at CSS Nite Osaka)
WHAT IS HTML5? (at CSS Nite Osaka)WHAT IS HTML5? (at CSS Nite Osaka)
WHAT IS HTML5? (at CSS Nite Osaka)
 
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
 
Consuming Java EE in Desktop, Web, and Mobile Frontends
Consuming Java EE in Desktop, Web, and Mobile FrontendsConsuming Java EE in Desktop, Web, and Mobile Frontends
Consuming Java EE in Desktop, Web, and Mobile Frontends
 

Recently uploaded

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Recently uploaded (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

HTML5 WebSocket Introduction

  • 1. HTML5 WebSocket Overview The Web Communication Revolution Reduced Complexity Web. Upgraded. High Performance Enterprise Support Marcelo Jabali Solutions Architect @mjabali July, 2012 1 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 2. Agenda  Introduction to HTML5 WebSocket  WebSocket API  WebSocket Protocol 2 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 3. About Me Marcelo Jabali Solutions Consultant marcelo.jabali@kaazing.com marcelojabali.blogspot.com mjabali linkedin.com/in/jabali 3 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 4. Architectural (R)evolution Legacy Web Half Duplex Full duplex Web Browser Web Middleware Back-end Tier server Living Web WebSocket Full duplex Web WebSocket Back-end Server server 4 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 5. Limitations of HTTP • Designed for document transfer • Request-response interaction • Bi-directional but still half-duplex • Traffic flows in only one direction at a time • Stateless • Header overhead information is sent with each HTTP request and response 5 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 6. Emulating full-duplex HTTP • AJAX (Asynchronous JavaScript + XML) • Content can change without loading the entire page • User-perceived low latency • Comet • Technique for server push • Lack of a standard implementation • Comet adds lots of complexity 6 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 7. Polling • Polling is "nearly real-time" • Used in Ajax applications to simulate real-time communication • Browser sends HTTP requests at regular intervals and immediately receives a response 7 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 8. Long Polling a/k/a Asynchronous polling • Browser sends a request to the server, server keeps the request open for a set period • Speed limited by response-request-response • Request/response headers add overhead on the wire 8 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 9. Streaming • More efficient, but sometimes problematic • Possible complications: o Proxies and firewalls o Response builds up and must be flushed periodically o Cross-domain issues to do with browser connection limits 9 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 10. HTTP Request Headers Client 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; 10 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 11. HTTP Response Headers Server 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 • Total overhead: 871 bytes (example) • Often 2K+ bytes • e.g. cookies 11 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 12. HTTP Header Traffic Analysis Client Overhead Bytes Overhead Mbps 1,000 871,000 ~6,6* 10,000 8,710,000 ~66 100,000 87,100,000 ~665 * 871,000 bytes = 6,968,000 bits = ~6.6 Mbps 12 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 13. Overhead… "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) 13 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 14. HTML5 WebSocket Overview 14 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 15. WebSocket History  Originally added to HTML5 specification as TCPConnection  Moved to its own specification later on 15 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 16. HTML5 WebSocket • W3C API and IETF Protocol • Leverages Cross-Origin Resource Sharing • Enables web pages to communicate with a remote host • Shares port with existing HTTP content • Allows unlimited connections per Origin • Unlike HTTP which is limited by convention • One WebSocket handshake in progress per Origin • Two schemes: • ws:// • wss:// 16 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 17. USING THE WEBSOCKET API 17 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 18. Checking for support JavaScript var status = document.getElementById("support"); if (window.WebSocket) { // or Modernizr.websocket status.innerHTML = "HTML5 WebSocket is supported"; } else { status.innerHTML = "HTML5 WebSocket is not supported"; } 18 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 19. Using the WebSocket API JavaScript //Create new WebSocket var mySocket = new WebSocket("ws://www.WebSocket.org"); // Associate listeners mySocket.onopen = function(evt) { }; mySocket.onclose = function(evt) { alert("closed w/ status: " + evt.code}; }; mySocket.onmessage = function(evt) { alert("Received message: " + evt.data); }; mySocket.onerror = function(evt) { alert("Error); }; 19 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 20. Using the WebSocket API JavaScript // Sending data mySocket.send("WebSocket Rocks!"); // Close WebSocket mySocket.close(); 20 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 21. WebSocket API Available? window.WebSocket or Modernizr.websocket Events onopen, onerror, onmessage Functions send, close Attributes url, readyState, bufferedAmount, extensions, protocol http://dev.w3.org/html5/websockets/ Italics: -08 and later 21 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 22. Browser Support Native: • Chrome 4+ • Safari 5+ • Firefox 4+ • Opera 10.7+ • Internet Explorer 10+ 22 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 23. WebSocket Servers Libraries  Kaazing • Misultin Client Libraries  Socket.io (node.js) • Cowboy • Web-socket-js (JavaScript)  Apache-websocket • YAWS • AS3 WebSocket (ActionScript)  Cramp • Juggernaut • .NET WebSocket client (.NET)  Nowjs • PHP Websocket • Anaida (.NET)  SockJS • websockify • WebSocket Sharp (.NET)  SuperWebSocket • ActiveMQ • Silverlight WebSocket client  Jetty • HornetMQ • Java WebSocket Client  Atmosphere • phpwebsocket • Arduino C++ WebSocket client  APE Project • Protocol::WebSocket • Ruby-web-socket  Xsockets  Orbited • em-websocket • ZTWebSocket (Objective-C)  Atmosphere • Jwebsocket • Libwebsockets (C)  Autobahn • WaterSprout Server  CouchDB • Pywebsocket  Netty • And more… 23 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 24. THE WEBSOCKET PROTOCOL 24 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 25. WebSocket Protocol History “draft-hixie-thewebsocketprotocol-xx” IETF Network Working Group Version Date Details -00 Jan. 9 2009 • Initial version -52 Oct. 23 2009 • Subprotocol concept introduced -76 May 6 2010 • Used in older browsers (FF4, etc.) “draft-ietf-hybi-thewebsocketprotocol-xx” (IETF HyBi Working Group) Version Date Details -01 Aug. 31 2010 • Added binary format -04 Jan. 11 2011 • Introduced data masking to address proxy server security issue • Introduced including protocol version number in handshake -14 Sep. 8 2011 • Guidance on version number negotiation RFC 6455 Dec. 2011 • Final version http://tools.ietf.org/html/rfc6455 25 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 26. WebSocket Handshake 26 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 27. WebSocket Frames • Have a few header bytes • Text or binary data • Frames are masked from client to server 27 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 28. WebSocket Frames Wireshark Trace of WebSocket Message (Client to Server) FIN bit, MASK bit, RSV bits, Op- payload mask payload Code length 81 85 CB 6E 9F 8E 83 0B F3 E2 A4 83 0B F3 E2 A4 XOR CB 6E 9F 8E CB -- -- -- -- -- 48 65 6C 6C 6F H e l l o 28 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 29. WebSocket Efficiency HTTP WebSocket Overhead 100s of bytes 2-6 bytes (typical) Latency New connection None: Use existing each time connection Latency Wait for next No waiting (polling) interval Latency None, if request No waiting (long polling) sent earlier + time to set up next request 29 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 30. Polling vs. WebSocket 30 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 31. Latency Reduction 31 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 32. WebSocket Benchmark Using Comet Using WebSocket http://webtide.intalio.com/2011/09/cometd-2-4-0-websocket-benchmarks/ 32 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 33. Why WebSocket? WebSocket is about…  Performance • WebSocket makes real-time communication much more efficient.  Simplicity • WebSocket makes communication between a client and server over the web much simpler.  Standards • WebSocket is an underlying network protocol that enables you to build other standard protocols on top of it.  HTML5 • WebSocket is part of an effort to provide advanced capabilities to HTML5 applications in order to compete with other platforms. 33 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 34. Demo – Mobile Notifications Notification Demo Examples 1. Gate Change Announcement 2. Flight Cancellation 3. Refund Request Process APNS Push Notification TCP/HTTP Cloud to Device Msg F Notifications ERP Refund CRM I Engine System R E HTML5 WebSocket W AL iOS/Android Native or L HTML5 Hybrid App Enterprise Messaging System / Apache ActiveMQ HTML5 WebSocket Flight Control Finance System Legend Background / Unidirectional Foreground / Bi-directional, Low Latency, Guaranteed Delivery 34 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 35. Q&A 35 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 36. 36 Copyright © 2012 Kaazing Corporation. All Rights Reserved.
  • 37. Copyright © 2011 Kaazing Corporation, All rights reserved. All materials, including labs and other handouts are property of Kaazing Corporation. Except when expressly permitted by Kaazing Corporation, you may not copy, reproduce, publish, or display any part of this training material, in any form, or by any means. 37 Copyright © 2012 Kaazing Corporation. All Rights Reserved.

Editor's Notes

  1. VNC Demo: http://vimeo.com/35557394
  2. Three ways to request info: polling, long-polling, and streaming
  3. http://caniuse.com/#search=WebSocket
  4. - Former author: Ian Hickson, Google- Current authors: Ian Fette, Google and Alexey Melnikov, Isode- Former IETF HyBi Working Group co-chair - Joe Hildebrand, Cisco- Current IETF HyBi Working Group co-chairs - Salvatore Loreto, Research Scientist, Ericsson Research, Finland - Gabriel Montenegro, Microsoft- Last Call notification: http://www.ietf.org/mail-archive/web/hybi/current/msg07725.html
  5. This is what the handshake looks like. If you use the WebSocket API, this is what happens under the covers. It's normal HTTP, and in the first part, the GET, there is an "upgrade" header asking for an upgrade to WebSocket. This header triggers a response from the server which agrees and returns a bunch of headers back to the client with the origin and information on how to establish the WebSocket connection.
  6. Once you have this WebSocket connection setup you can start sending WebSocket frames. Again, you don't have to worry about creating these frames, you just use the WebSocket API to send your message – this is done under the covers. Your message is taken and put into a WebSocket "frame" that starts with hex-0 and ends with hex-FF bytes, and contains your data in UTF-8 format.You send this data along and effectively there's no real limit to how much data you can send. All of the chunking and lower-level stuff is done for you by the protocol. When binary support is added, the protocol will most likely add a length prefix because binary data may contain hex-0 and hex-FF bytes.
  7. Remember when we looked at HTTP earlier and saw an example with 871 bytes of header data? For WebSocket that number is 2 bytes. It's always fixed at 2 bytes while HTTP is variable. So you're going from 871 bytes to 2, which is huge reduction in overhead.We didn't explicitly cover it before, but each HTTP message is a brand new TCP connection which comes with some overhead. WebSockets maintain the same TCP connection. So you have two nice advantage of WebSocket over HTTP.
  8. Here is a graphical view of the data which shows the dramatic reduction in overhead relative to Ajax or Comet for any number of clients.
  9. Additionally you have a huge latency reduction because every time, as you can see in the polling example, you have a request and response. And each time a request has to be fired from the client. In the meantime, once the WebSocket upgrade has passed and WebSocket connection is established, the server can send messages at will. It doesn't have to wait for a request from the client.So you get 3x improvement in latency with WebSocket.
  10. Run by the Jetty folks on their optimized Comet server. Emulated a chatroom on EC2. Left: Comet implementation, 2-4ms latency for 5-50K emulated clients @ 10Kmessages/sec. Starts climbing linearly from there up to around 180ms @ 50K messages/sec, except for the 50K client case (hits an internal network limit @ Amazon.)Right: WebSocket implementation of same. 2-4ms latency for all cases _except_ a new 200K client setting that looked like it would start hitting the same internal network limit. (4x as many client, still 5-6 msec.)