SlideShare una empresa de Scribd logo
1 de 101
Descargar para leer sin conexión
HTML5Realtime and
                                      WebSocket
                                       Code Lab
                                                          @peterlubbers
                                                           @franksalim
1   © 2011 – Kaazing Corporation    ALL RIGHTS RESERVED
                                                               Kaazing
WebSocket Demo




                                                  http://demo.kaazing.com/racer/
 2   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
WebSocket Demo

 • Plink: http://labs.dinahmoe.com/plink/#




 3   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
WebSocket Demos
FX Trader Application Demo
http://demo.kaazing.me/forex




   4     © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Example: CollectdViewer
Server Monitor System
http://bergmans.com/WebSocket/collectdViewer.html




  5     © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
WebSocket Demos
Rawkets
http://www.rawkets.com




 6     © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
About @peterlubbers
 • Sr. Director Technical Communication
   Kaazing (we’re hiring)
 • Author, Pro HTML5 Programming
 • Founder San Francisco HTML5 User
   Group
 • HTML5… it’s how I roll




 7   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
About @franksalim

 •   Senior Software Engineer, Kaazing
 •   Author, Pro HTML5 Programming
 •   Code-Generating Human
 •   http://franksalim.com/
 •   HTML5… it’s how I roll




 8    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Agenda

 • Introduction to WebSocket
 •WebSocket API
                                                            #sfhtml5
 •WebSocket Protocol                                        #gtugsf
                                                          @peterlubbers
 • Protocol Communication                                 @franksalim

 • Real-World WebSocket




 9   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Introduction to WebSocket




10   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Networked Applications


 • On the LAN: Reliable, real-time communication
 • On the web: ?
   • Mostly idle
   • Mostly broadcast
   • Nearly real-time
 • Web + WebSockets = reliable and real-time




 11   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Approaches

 • HTTP-based
 • WebSockets




 12   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
HTTP



13   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
HTTP


 • HTTP is half-duplex
      • Traffic flows in only one direction at a time
      • Bidirectional communications are complicated to
        manage
 • HTTP is stateless
      • Redundant information is
        sent with each HTTP
        request and response




 14    © 2011 – 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




 15      © 2011 – 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




 16   © 2011 – 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




 17   © 2011 – 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




 18    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Comet Polling Example




 19   © 2011 – 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;




 20      © 2011 – 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


 21       © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Upload/Download Ratios

 • Most users have Internet connections where
   upload to download ratios are between 1:4
   and 1:20
      • Result: 500 byte
       HTTP request header
       request could
       take as long
       to upload as
       10 kB of HTTP
       response data
       takes to download


 22    © 2011 – 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




 23   © 2011 – Kaazing Corporation         ALL RIGHTS RESERVED
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)




 24    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Enter HTML5 WebSocket!




25    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
History


 Or, what do WebSocket and model trains have in
   common?




 26   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
WebSocket History


 • Originally added to HTML5 Spec as
   TCPConnection
 • Moved to its
   own specification




 27   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
HTML5 WebSocket


• Cross-web communications w/ remote host
      •   Full-duplex (bi-directional), single socket
      •   Shares port with existing HTTP content
      •   Traverses firewalls and proxies
      •   ws:// and wss://
• W3C API (Javascript)
• IETF Protocol




 28       © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
USING THE WEBSOCKET API


29    © 2011 – 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";
      }




 30      © 2011 – 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);
       };


  31      © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Using the WebSocket API


JavaScript


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

       // Close WebSocket
       mySocket.close();




  32      © 2011 – 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
 33   © 2011 – Kaazing Corporation      ALL RIGHTS RESERVED
Browser Support
 Native:                                     Emulation:
 • Chrome 4+                                 • Kaazing WebSocket
 • Safari 5+                                   Gateway
 • Firefox 4+                                • socket.io

 • Opera 10.7+                               • SockJS

 • Internet Explorer 10+                     • web-socket.js (Flash)

                                                    http://caniuse.com/#search=W
                                                                         ebSocket




 34   © 2011 – 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
•    Nowjs                              •   PHP Websocket
                                                                        (.NET)
•    SockJS                             •   websockify
                                                                    •   Anaida (.NET)
•    SuperWebSocket                     •   ActiveMQ
                                                                    •   WebSocket Sharp (.NET)
•                                       •   HornetMQ
     Jetty                                                          •   Silverlight WebSocket client
                                        •   phpwebsocket
•    Atmosphere                                                     •   Java WebSocket Client
                                        •   Protocol::WebSocket
•    APE Project                                                    •   Arduino C++ WebSocket
                                        •   em-websocket                client
•    Xsockets
                                        •   Jwebsocket              •   Ruby-web-socket
•    Orbited                            •   WaterSprout Server      •   ZTWebSocket (Objective-
•    Atmosphere                         •   Pywebsocket                 C)
•    Autobahn                           •   And more…               •   Libwebsockets (C)
•    CouchDB
•    Netty

35       © 2011 – Kaazing Corporation         ALL RIGHTS RESERVED
WebSocket Emulation

 •        Kaazing WebSocket Gateway
          • http://www.kaazing.com/download
          • Makes WebSocket work in all browsers today (including
            I.E. 6)
 •        Flash WebSocket implementation
          • http://github.com/gimite/web-socket-js
          • Requires opening port on the server's firewall
      •   Socket.io
          •        http://socket.io
          •        Alternate API
          •        Adds heartbeat, timeouts and disconnection
          •        Uses Flash when available
 36           © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Debugging in Chrome




 37   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Debugging in Chrome




 38   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Lab Preview
WebSocket Basics
Ingredients:
      • WebSocket-aware browser (Latest Chrome, Firefox)
      • Python-based server (localhost or cloud)
      • Web page w/ Javascript
Steps:
      • Edit the page to check for browser support
      • Add form handler to send messages to server
      • See WebSockets in action!




 39      © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Lab:
                  WebSocket Basics




40   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
THE WEBSOCKET PROTOCOL


41    © 2011 – 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
 42    © 2011 – Kaazing Corporation       ALL RIGHTS RESERVED
WebSocket Handshake




 43   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
WebSocket Frames

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




 44      © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
WebSocket Frames
Wireshark Trace of WebSocket Basics Lab Message (Client to Server)




                                        FIN bit,    MASK
                                       RSV bits, bit, payload       mask             payload
                                       Op-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

  45    © 2011 – Kaazing Corporation          ALL RIGHTS RESERVED
WebSocket Frames
Wireshark Trace of WebSocket Basics Lab Message (Server to Client)




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

                                                                81 05 48 65 6C 6C 6F
                                                                    H e l l o




  46    © 2011 – 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

 47   © 2011 – Kaazing Corporation           ALL RIGHTS RESERVED
WebSocket Framing Analysis



         Client                            Overhead Bytes Overhead Mbps

         1,000                                                 2,000     ~0.015*

         10,000                                             20,000           ~0.153

         100,000                                         200,000             ~1.526




                                 * 2,000 bytes = 16,000 bits (~0.015 Mbps)




 48   © 2011 – Kaazing Corporation             ALL RIGHTS RESERVED
Polling vs. WebSocket




 49   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Latency Reduction




 50   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
WebSocket Benchmark


           Using Comet                                         Using WebSocket




                  http://webtide.intalio.com/2011/09/cometd-2-4-0-websocket-benchmarks/
 51   © 2011 – Kaazing Corporation       ALL RIGHTS RESERVED
WebSocket Summary

 • Extends network applications across the web
      • Desktop apps
      • Browser-based apps
      • Mobile apps
 • Far more efficient than HTTP
 • Part of the HTML5 Standard
 • Older browsers can play too




 52    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Bonus Lab:
     Network Traffic Analysis




53   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
PROTOCOL COMMUNICATION


54    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED   Photo credit: zbigphotography
Using WebSocket…

• Extends legacy systems to the web
      • Message brokers, databases, etc.
• Extends client-server protocols to the web:
      •   XMPP, Jabber
      •   Pub/Sub (Stomp/AMQP)
      •   Gaming protocols
      •   Any TCP-based protocol
      •   RFB/VNC
• Your browser becomes a
  first-class network citizen

 55       © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Traditional Architecture




 56   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
WebSocket Architecture




 100%
Hipster




  57   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
“Why?”

 • Better responsiveness
 • Better scalability
      • Less traffic on the wire
      • Less work for the server
 • Easier back-end development
      • Custom commands = better match to your needs
 • Easier migration of existing systems
      • Just a new UI




 58    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Protocols

 • XMPP
 • STOMP
 • More…




 59   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
XMPP

 • XMPP (Extensible Messaging and Presence
   Protocol)
     • Open XML technology for presence and real-time
       communication
     • Developed by the Jabber community in 1999
     • Formalized by the IETF in 2002-2004
 • Uses
     • Real-time chat
     • Client-Server
 • Examples: Google Talk, iChat, Facebook

60    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
XMPP XML

       XML

      <?xml version='1.0'?>
                                        Client  Server
      <stream:stream
       to='example.com'
       xmlns='jabber:client'
       xmlns:stream='http://etherx.jabber.org/streams'
       version='1.0'>

      <?xml version='1.0'?>
      <stream:stream                    Server Client
      from='example.com'                plus
                                        encryption, authenticat
       id='someid'
                                        ion, and resource
      xmlns='jabber:client'             binding
       xmlns:stream='http://etherx.jabber.org/streams'
       version='1.0'>

 61          © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
XMPP Conversation

       XML

      <?xml version='1.0'?>
                                        Client  Server
      <message from='rocky@example.com'
         to='sean@example.com'
         xml:lang='en'>
      <body>Hi Sean!</body>
      </message>

      <?xml version='1.0'?>
      <message from='sean@example.com'
                                       Server Client
       to='rocky@kaazing.com'
         xml:lang='en'>
      <body>Hi Rocky!</body>
      </message>


 62          © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
XMPP Command Set

 •    Connect / disconnect
 •    Register
 •    Check roster
 •    Sendmessages
 •    Set status
 •    Communicatepresence
 •    + extensions




 63    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
XMPP over WebSocket
 draft-moffitt-xmpp-over-websocket-00
 Proposed protocol:
      •      Add xmpp to Sec-WebSocket-Protocol header
      •      Commands: regular XMPP XML
      •      Stanzas: 1 per WebSocket frame
      •      Keepalive: WebSocket PING command
      •      Shutdown:
               • Close XMPP stream normally
               • Close WebSocket connection




 64       © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Google Talk

 • Google Talk
      •      Encrypted (XMPP over TLS)
      •      Integrates w/ any service provider using XMPP
      •      Hosted at talk.google.com on port 5222
      •      Authenticationthrough SASL PLAIN
 • example: http://kaazing.me




 65       © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
MESSAGE BROKERS AND
     STOMP

66    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
STOMP
stomp.github.com

  • Streaming Text Oriented Messaging Protocol
       • Simple, easily-implemented protocol for use with
         message brokers
       • Provides an interoperable wire format
       • STOMP clients can communicate w/ almost every
         available message broker




  67    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Apache ActiveMQ

 • Open source
   message broker
   and JMS provider
 • Provides a
   publish-subscribe model based on JMS (Java
   Message Service) specification
 • Includes built-in support for STOMP




 68   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
STOMP and WebSocket

 • Direct link between                            STOMP + WebSocket Providers
                                                  stomp-websocket
   the browser & JMS
                                                  Stomple
   broker                                         Apache ActiveMQ
 • Radically simplified                           TorqueBox (Ruby)
   application design                             Kaazing Web Gateway JMS edition




 69   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
STOMP Protocol
Specification @ Github

  Message Structure                                  Client        Server
  •     Frame-based                                  Commands      Responses
                                                     ABORT         ERROR
  •     Request-response
                                                     ACK           MESSAGE
  •     Heartbeat optional
                                                     BEGIN         RECEIPT
                                                     COMMIT

       COMMAND                                       CONNECT
       header1:value1                                DISCONNECT
       header2:value2                                SEND
                                                     SUBSCRIBE
       Body^@                                        UNSUBSCRIBE




  70      © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Lab Preview
Protocol Libraries




 71   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Lab Preview
Protocol Libraries
Ingredients:
      • Safari 5.0+ Browser
         • Others not guaranteed
      • Apache web server (httpd)
         • Pre-installed on OS X, Windows installer provided
      • Apache ActiveMQ (localhost or cloud)
         • IMPORTANT: Add stomp and websocket transport connectors
      • Stock data source
      • Starter files
         • stomp-websocket library
         • HTML & CSS starters


 72      © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Lab:
                    Protocol Libraries




73   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
WEBSOCKETS IN THE
     REAL WORLD

74    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Security




75   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Security

 • Components of secure communication :
      1.        Transport Layer
      2.        Authentication
      3.        Authorization
      4.        Origin-BasedSecurity and CORS




 76        © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Transport Layer Security (TLS)


• Also known as SSL (Secure Socket Layer)
  support
• HTTP over TLS is called HTTPS
      o Default port is 443
      o HTTPS is not a separate protocol
      o An HTTPS connection is established after a successful
        TLS handshake (using public and private key
        certificates)




 77      © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
ws:// and wss:// schemes




 78   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Authentication

 • Mechanism by which systems identify users
   and check whether users really are who they
   represent themselves to be

 • Authentication process
      Step 1) Server issues a challenge using the HTTP 401
              Authorization Requiredcode
      Step 2) Client responds by providing the requested
              authentication information if it can



 79    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Authorization

 • Mechanism by which a system determines
   users’ level of access
      o For example, a web page can have viewer,
        moderator, and administrator privileges
 • Access rights are typically stored in the policy
   store that is associated with the application




 80    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Web Origin Concept

 • Web Origin Concept RFC 6454:
   http://www.ietf.org/rfc/rfc6454.txt
 • An Origin is a subset of an address used for
   modeling trust relationships on the web
 • Origins consist of a scheme, a host, and a port:
      • Scheme: http:, https:, ws:, wss:
      • Host: www.example.com, img.example.com,
        192.0.2.10
      • Port: 80, 443



 81    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Same-Origin Policy
 “Generally speaking, documents retrieved from
  distinct origins are isolated from each other” –
  W3C
  http://www.w3.org/Security/wiki/Same_Origin_Policy

 • Browsers prevent a script or document loaded
    from one origin from communicating with a
    document loaded from another origin
 • Original security model for HTML
      • Introduced in Netscape Navigator 2.0
      • Too limiting in this age of client-side web apps




 82     © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Origin Quiz


 Which URLs have the same Origin?
      1.      http://www.example.com/index.html
      2.      https://www.example.com/index.html
      3.      http://img.example.com/html5.png
      4.      http://www.example.com:8080/page2.html
      5.      http://192.0.2.10:80/index.html*
      6.      http://www.example.com/about.html


      *      Where 192.0.2.10 resolves to www.example.com



 83       © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
CORS




                                                          enable-cors.org



84   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Cross-Origin Requests

 • Have an Originheader
      •      Contains the request’s origin
      •      Produced by the browser
      •      Cannot be changed by application code
      •      Differs from referer[sic]: refereris a complete
             URL (can include full path)
 • Originating page’s server must approve
   (Access-Control-Allow-* headers)




 85       © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
CORS




86   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Intermediaries




87   © 2011 – Kaazing Corporation      ALL RIGHTS RESERVED
Types of Proxy Servers




                                     http://www.infoq.com/articles/Web-Sockets-Proxy-Servers
 88   © 2011 – Kaazing Corporation            ALL RIGHTS RESERVED
Proxy Servers

      • WebSocket protocol is unaware of proxy
        servers and firewalls
        •         HTTP-based handshake
       Proxy type                          Connection        Outcome
       Explicit                            Unencrypted       1. HTTP CONNECT
                                                             2.WebSocket connection flows to
       Explicit                            Encrypted         destination
       Transparent                         Unencrypted       Proxy strips extra headers,
                                                             connection fails
       Transparent                         Encrypted         Connection tunnels past proxy




 89         © 2011 – Kaazing Corporation                 ALL RIGHTS RESERVED
Proxy Traversal Tree




 Case 2 Unencrypted
                                                                   Case 3 Encrypted
 WebSocket Connections
                                                                   WebSocket
 and Transparent Proxy
                                                                   Connections and
 Servers
                                                                   Explicit Proxy Servers


Case 1 Unencrypted
WebSocket Connections
and Explicit Proxy                                                    Case 4 Encrypted
Servers                                                               WebSocket
                                                                      Connections and
                                                                      Transparent Proxy
                                                                      Servers


     90       © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Load Balancing Routers

 1. TCP(layer-4) work well withWebSockets
 2. HTTP (Layer 7) expect HTTP traffic, can get
    confused by WebSocket upgrade traffic.
    May need to be configured to be explicitly
    aware of WebSockettraffic.




 91   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Firewalls

 • Usually no specific WebSocketconcerns
 • Stateful packet inspection may need to know
   about WS protocol (or use WSS)




 92   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Twitter: @peterlubbers, @franksalim

93   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Learn More…
• HTML5 User Groups:
     • San Francisco: http://www.sfhtml5.org/
• Apress book: Pro HTML5 Programming
     • (Peter Lubbers, Brian Albers, & Frank Salim)
       http://www.prohtml5.com/
• Kaazing Corporation–Training:
     • http://kaazing.com/training/




94     © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Questions and Answers




95   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
More HTML5 Code Labs!

 • Series of three Code Labs:
      • March 10
      • April7 (Mobile with PPK)
      • May 5 (HTML Cinco! Geolocation)
 • In conjunction with GTUGSF
 • Sign up:
   http://GTUGsf.com/HTML5




 96    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Buy the Book!


 • Pro HTML5 Programming (Apress, 2011)
 • 50% off e-book coupon code:
   50OFFHTML5
   http://goo.gl/Dzq4A




 97   © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Additional Resources

 •    Scheme host port blog (Adam Barth):
      http://www.schemehostport.com/
 •    SPDY Essentials (Google Tech Talk):
      http://goo.gl/IcVdF
 •    Breaking the Cross Domain Barrier (Alex Slexton):
      http://goo.gl/IcVdF
 •    HTML5 Realtime and Connectivity video by Peter Lubbers:
      http://marakana.com/s/html_real-time,1066/index.html
 •    XHR Level 2 Article (Eric Bidelman):
      http://www.html5rocks.com/en/tutorials/file/xhr2/
 •    HTML5 Weekly:
      http://html5weekly.com/
 •    The Web Ahead Podcasts:
      http://5by5.tv/webahead/
 98     © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
Get Trained!

  Proven, practical worldwide HTML5 Training
   (from experts, not just trainers):
      • E-mail us: training@kaazing.com
      • Web site: http://kaazing.com/training/




 99    © 2011 – Kaazing Corporation   ALL RIGHTS RESERVED
-
100   © 2011 – 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.




101   © 2011 – Kaazing Corporation            ALL RIGHTS RESERVED

Más contenido relacionado

La actualidad más candente

Kafka Streams State Stores Being Persistent
Kafka Streams State Stores Being PersistentKafka Streams State Stores Being Persistent
Kafka Streams State Stores Being Persistentconfluent
 
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZerStd 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZerNuzhat Memon
 
MQTT - A practical protocol for the Internet of Things
MQTT - A practical protocol for the Internet of ThingsMQTT - A practical protocol for the Internet of Things
MQTT - A practical protocol for the Internet of ThingsBryan Boyd
 
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...Flink Forward
 
Message queuing telemetry transport (mqtt) message format
Message queuing telemetry transport (mqtt) message formatMessage queuing telemetry transport (mqtt) message format
Message queuing telemetry transport (mqtt) message formatHamdamboy (함담보이)
 
Using Spark Streaming and NiFi for the next generation of ETL in the enterprise
Using Spark Streaming and NiFi for the next generation of ETL in the enterpriseUsing Spark Streaming and NiFi for the next generation of ETL in the enterprise
Using Spark Streaming and NiFi for the next generation of ETL in the enterpriseDataWorks Summit
 
Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSocketsGunnar Hillert
 
[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging QueuesNaukri.com
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaJiangjie Qin
 
HTTP/3, QUIC and streaming
HTTP/3, QUIC and streamingHTTP/3, QUIC and streaming
HTTP/3, QUIC and streamingDaniel Stenberg
 
Simple Object Access Protocol
Simple Object Access ProtocolSimple Object Access Protocol
Simple Object Access ProtocolSaatviga Sudhahar
 
Getting Started with Confluent Schema Registry
Getting Started with Confluent Schema RegistryGetting Started with Confluent Schema Registry
Getting Started with Confluent Schema Registryconfluent
 
email transaction network analysis
email transaction network analysisemail transaction network analysis
email transaction network analysiskeithpjolley
 

La actualidad más candente (20)

Kafka Streams State Stores Being Persistent
Kafka Streams State Stores Being PersistentKafka Streams State Stores Being Persistent
Kafka Streams State Stores Being Persistent
 
RabbitMQ
RabbitMQ RabbitMQ
RabbitMQ
 
REST vs. SOAP
REST vs. SOAPREST vs. SOAP
REST vs. SOAP
 
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZerStd 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
 
RabbitMQ.ppt
RabbitMQ.pptRabbitMQ.ppt
RabbitMQ.ppt
 
MQTT - A practical protocol for the Internet of Things
MQTT - A practical protocol for the Internet of ThingsMQTT - A practical protocol for the Internet of Things
MQTT - A practical protocol for the Internet of Things
 
HTTP Basics
HTTP BasicsHTTP Basics
HTTP Basics
 
Amqp Basic
Amqp BasicAmqp Basic
Amqp Basic
 
Intro to WebSockets
Intro to WebSocketsIntro to WebSockets
Intro to WebSockets
 
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
 
Message queuing telemetry transport (mqtt) message format
Message queuing telemetry transport (mqtt) message formatMessage queuing telemetry transport (mqtt) message format
Message queuing telemetry transport (mqtt) message format
 
Using Spark Streaming and NiFi for the next generation of ETL in the enterprise
Using Spark Streaming and NiFi for the next generation of ETL in the enterpriseUsing Spark Streaming and NiFi for the next generation of ETL in the enterprise
Using Spark Streaming and NiFi for the next generation of ETL in the enterprise
 
Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSockets
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache Kafka
 
HTTP/3, QUIC and streaming
HTTP/3, QUIC and streamingHTTP/3, QUIC and streaming
HTTP/3, QUIC and streaming
 
Simple Object Access Protocol
Simple Object Access ProtocolSimple Object Access Protocol
Simple Object Access Protocol
 
Getting Started with Confluent Schema Registry
Getting Started with Confluent Schema RegistryGetting Started with Confluent Schema Registry
Getting Started with Confluent Schema Registry
 
email transaction network analysis
email transaction network analysisemail transaction network analysis
email transaction network analysis
 

Destacado

Using RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocolUsing RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocolTho Q Luong Luong
 
Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSocketsWASdev Community
 
Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Arun Gupta
 
Intro lecture: Theory and method for media technology
Intro lecture: Theory and method for media technologyIntro lecture: Theory and method for media technology
Intro lecture: Theory and method for media technologyhrastinski
 
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Nathan O'Hanlon
 
Websockets in Node.js - Making them reliable and scalable
Websockets in Node.js - Making them reliable and scalableWebsockets in Node.js - Making them reliable and scalable
Websockets in Node.js - Making them reliable and scalableGareth Marland
 
Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015
Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015
Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015Rich Cullen
 
Netflix at-disney-09-26-2014
Netflix at-disney-09-26-2014Netflix at-disney-09-26-2014
Netflix at-disney-09-26-2014Monal Daxini
 
JSON-RPC - JSON Remote Procedure Call
JSON-RPC - JSON Remote Procedure CallJSON-RPC - JSON Remote Procedure Call
JSON-RPC - JSON Remote Procedure CallPeter R. Egli
 
Starting from Scratch with the MEAN Stack
Starting from Scratch with the MEAN StackStarting from Scratch with the MEAN Stack
Starting from Scratch with the MEAN StackMongoDB
 
Data Distribution Service Security and the Industrial Internet of Things
Data Distribution Service Security and the Industrial Internet of ThingsData Distribution Service Security and the Industrial Internet of Things
Data Distribution Service Security and the Industrial Internet of ThingsReal-Time Innovations (RTI)
 
REST vs. Messaging For Microservices
REST vs. Messaging For MicroservicesREST vs. Messaging For Microservices
REST vs. Messaging For MicroservicesEberhard Wolff
 
The Data Distribution Service Tutorial
The Data Distribution Service TutorialThe Data Distribution Service Tutorial
The Data Distribution Service TutorialAngelo Corsaro
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)Ericom Software
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityPeter Lubbers
 

Destacado (17)

Using RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocolUsing RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocol
 
Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSockets
 
Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014
 
Intro lecture: Theory and method for media technology
Intro lecture: Theory and method for media technologyIntro lecture: Theory and method for media technology
Intro lecture: Theory and method for media technology
 
WebSocket protocol
WebSocket protocolWebSocket protocol
WebSocket protocol
 
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
 
Websockets in Node.js - Making them reliable and scalable
Websockets in Node.js - Making them reliable and scalableWebsockets in Node.js - Making them reliable and scalable
Websockets in Node.js - Making them reliable and scalable
 
Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015
Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015
Top 10 real life WebSocket use cases & experiences - Devoxx UK 2015
 
Netflix at-disney-09-26-2014
Netflix at-disney-09-26-2014Netflix at-disney-09-26-2014
Netflix at-disney-09-26-2014
 
JSON-RPC - JSON Remote Procedure Call
JSON-RPC - JSON Remote Procedure CallJSON-RPC - JSON Remote Procedure Call
JSON-RPC - JSON Remote Procedure Call
 
Starting from Scratch with the MEAN Stack
Starting from Scratch with the MEAN StackStarting from Scratch with the MEAN Stack
Starting from Scratch with the MEAN Stack
 
Data Distribution Service Security and the Industrial Internet of Things
Data Distribution Service Security and the Industrial Internet of ThingsData Distribution Service Security and the Industrial Internet of Things
Data Distribution Service Security and the Industrial Internet of Things
 
REST vs. Messaging For Microservices
REST vs. Messaging For MicroservicesREST vs. Messaging For Microservices
REST vs. Messaging For Microservices
 
DDS and XMPP
DDS and XMPPDDS and XMPP
DDS and XMPP
 
The Data Distribution Service Tutorial
The Data Distribution Service TutorialThe Data Distribution Service Tutorial
The Data Distribution Service Tutorial
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
 

Similar a HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)

Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
Camelone-2012 HTML5 WebSocket ActiveMQ/CamelCamelone-2012 HTML5 WebSocket ActiveMQ/Camel
Camelone-2012 HTML5 WebSocket ActiveMQ/CamelCharles Moulliard
 
HTML5 WebSocket Introduction
HTML5 WebSocket IntroductionHTML5 WebSocket Introduction
HTML5 WebSocket IntroductionMarcelo Jabali
 
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
 
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
 
V2 peter-lubbers-sf-jug-websocket
V2 peter-lubbers-sf-jug-websocketV2 peter-lubbers-sf-jug-websocket
V2 peter-lubbers-sf-jug-websocketbrent bucci
 
Peter lubbers-html5-offline-web-apps
Peter lubbers-html5-offline-web-appsPeter lubbers-html5-offline-web-apps
Peter lubbers-html5-offline-web-appsSkills Matter
 
Top 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersTop 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersBrian Huff
 
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
 
Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010sullis
 
Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15streamdata.io
 
HTML5 Offline Web Applications (Silicon Valley User Group)
HTML5 Offline Web Applications (Silicon Valley User Group)HTML5 Offline Web Applications (Silicon Valley User Group)
HTML5 Offline Web Applications (Silicon Valley User Group)robinzimmermann
 
Past, Present and Future of WebSocket - HTML5DevConf May 2014
Past, Present and Future of WebSocket - HTML5DevConf May 2014Past, Present and Future of WebSocket - HTML5DevConf May 2014
Past, Present and Future of WebSocket - HTML5DevConf May 2014Frank Greco
 
HTML5--The 30,000' View (A fast-paced overview of HTML5)
HTML5--The 30,000' View (A fast-paced overview of HTML5)HTML5--The 30,000' View (A fast-paced overview of HTML5)
HTML5--The 30,000' View (A fast-paced overview of HTML5)Peter Lubbers
 
Web sockets - Pentesting
Web sockets - Pentesting Web sockets - Pentesting
Web sockets - Pentesting Vandana Verma
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkFabio Tiriticco
 
Html5 Application Security
Html5 Application SecurityHtml5 Application Security
Html5 Application Securitychuckbt
 
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
 

Similar a HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF) (20)

Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
Camelone-2012 HTML5 WebSocket ActiveMQ/CamelCamelone-2012 HTML5 WebSocket ActiveMQ/Camel
Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
 
HTML5 WebSocket Introduction
HTML5 WebSocket IntroductionHTML5 WebSocket Introduction
HTML5 WebSocket Introduction
 
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)
 
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
 
V2 peter-lubbers-sf-jug-websocket
V2 peter-lubbers-sf-jug-websocketV2 peter-lubbers-sf-jug-websocket
V2 peter-lubbers-sf-jug-websocket
 
Peter lubbers-html5-offline-web-apps
Peter lubbers-html5-offline-web-appsPeter lubbers-html5-offline-web-apps
Peter lubbers-html5-offline-web-apps
 
Top 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersTop 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud Developers
 
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
 
Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010
 
Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15
 
Future of web_apps
Future of web_appsFuture of web_apps
Future of web_apps
 
HTML5 Offline Web Applications (Silicon Valley User Group)
HTML5 Offline Web Applications (Silicon Valley User Group)HTML5 Offline Web Applications (Silicon Valley User Group)
HTML5 Offline Web Applications (Silicon Valley User Group)
 
Past, Present and Future of WebSocket - HTML5DevConf May 2014
Past, Present and Future of WebSocket - HTML5DevConf May 2014Past, Present and Future of WebSocket - HTML5DevConf May 2014
Past, Present and Future of WebSocket - HTML5DevConf May 2014
 
HTML5--The 30,000' View (A fast-paced overview of HTML5)
HTML5--The 30,000' View (A fast-paced overview of HTML5)HTML5--The 30,000' View (A fast-paced overview of HTML5)
HTML5--The 30,000' View (A fast-paced overview of HTML5)
 
Websocket shanon
Websocket shanonWebsocket shanon
Websocket shanon
 
Web sockets - Pentesting
Web sockets - Pentesting Web sockets - Pentesting
Web sockets - Pentesting
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
 
Html5 Application Security
Html5 Application SecurityHtml5 Application Security
Html5 Application Security
 
HTML5 Overview (Silicon Valley User Group)
HTML5 Overview (Silicon Valley User Group)HTML5 Overview (Silicon Valley User Group)
HTML5 Overview (Silicon Valley User Group)
 
Real Time With Web Sockets
Real Time With Web SocketsReal Time With Web Sockets
Real Time With Web Sockets
 

Más de Peter Lubbers

Peter lubbers-html5-overview-sf-dev-conf-2011
Peter lubbers-html5-overview-sf-dev-conf-2011Peter lubbers-html5-overview-sf-dev-conf-2011
Peter lubbers-html5-overview-sf-dev-conf-2011Peter Lubbers
 
HTML5: The Next Internet Goldrush
HTML5: The Next Internet GoldrushHTML5: The Next Internet Goldrush
HTML5: The Next Internet GoldrushPeter Lubbers
 
HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebPeter Lubbers
 
Los Angeles HTML5 User Group Meeting Ask the Expert Session
Los Angeles HTML5 User Group Meeting Ask the Expert SessionLos Angeles HTML5 User Group Meeting Ask the Expert Session
Los Angeles HTML5 User Group Meeting Ask the Expert SessionPeter Lubbers
 
HTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedHTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedPeter Lubbers
 

Más de Peter Lubbers (6)

Peter lubbers-html5-overview-sf-dev-conf-2011
Peter lubbers-html5-overview-sf-dev-conf-2011Peter lubbers-html5-overview-sf-dev-conf-2011
Peter lubbers-html5-overview-sf-dev-conf-2011
 
High-Speed HTML5
High-Speed HTML5High-Speed HTML5
High-Speed HTML5
 
HTML5: The Next Internet Goldrush
HTML5: The Next Internet GoldrushHTML5: The Next Internet Goldrush
HTML5: The Next Internet Goldrush
 
HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the Web
 
Los Angeles HTML5 User Group Meeting Ask the Expert Session
Los Angeles HTML5 User Group Meeting Ask the Expert SessionLos Angeles HTML5 User Group Meeting Ask the Expert Session
Los Angeles HTML5 User Group Meeting Ask the Expert Session
 
HTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedHTML5 Web Workers-unleashed
HTML5 Web Workers-unleashed
 

Último

Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
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
 

Último (20)

Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
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
 

HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)

  • 1. HTML5Realtime and WebSocket Code Lab @peterlubbers @franksalim 1 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED Kaazing
  • 2. WebSocket Demo http://demo.kaazing.com/racer/ 2 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 3. WebSocket Demo • Plink: http://labs.dinahmoe.com/plink/# 3 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 4. WebSocket Demos FX Trader Application Demo http://demo.kaazing.me/forex 4 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 5. Example: CollectdViewer Server Monitor System http://bergmans.com/WebSocket/collectdViewer.html 5 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 6. WebSocket Demos Rawkets http://www.rawkets.com 6 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 7. About @peterlubbers • Sr. Director Technical Communication Kaazing (we’re hiring) • Author, Pro HTML5 Programming • Founder San Francisco HTML5 User Group • HTML5… it’s how I roll 7 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 8. About @franksalim • Senior Software Engineer, Kaazing • Author, Pro HTML5 Programming • Code-Generating Human • http://franksalim.com/ • HTML5… it’s how I roll 8 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 9. Agenda • Introduction to WebSocket •WebSocket API #sfhtml5 •WebSocket Protocol #gtugsf @peterlubbers • Protocol Communication @franksalim • Real-World WebSocket 9 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 10. Introduction to WebSocket 10 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 11. Networked Applications • On the LAN: Reliable, real-time communication • On the web: ? • Mostly idle • Mostly broadcast • Nearly real-time • Web + WebSockets = reliable and real-time 11 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 12. Approaches • HTTP-based • WebSockets 12 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 13. HTTP 13 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 14. HTTP • HTTP is half-duplex • Traffic flows in only one direction at a time • Bidirectional communications are complicated to manage • HTTP is stateless • Redundant information is sent with each HTTP request and response 14 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 15. 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 15 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 16. 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 16 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 17. 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 17 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 18. 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 18 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 19. Comet Polling Example 19 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 20. 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; 20 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 21. 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 21 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 22. Upload/Download Ratios • Most users have Internet connections where upload to download ratios are between 1:4 and 1:20 • Result: 500 byte HTTP request header request could take as long to upload as 10 kB of HTTP response data takes to download 22 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 23. 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 23 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 24. 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) 24 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 25. Enter HTML5 WebSocket! 25 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 26. History Or, what do WebSocket and model trains have in common? 26 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 27. WebSocket History • Originally added to HTML5 Spec as TCPConnection • Moved to its own specification 27 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 28. HTML5 WebSocket • Cross-web communications w/ remote host • Full-duplex (bi-directional), single socket • Shares port with existing HTTP content • Traverses firewalls and proxies • ws:// and wss:// • W3C API (Javascript) • IETF Protocol 28 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 29. USING THE WEBSOCKET API 29 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 30. 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"; } 30 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 31. 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); }; 31 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 32. Using the WebSocket API JavaScript // Sending data mySocket.send("WebSocket Rocks!"); // Close WebSocket mySocket.close(); 32 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 33. 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 33 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 34. Browser Support Native: Emulation: • Chrome 4+ • Kaazing WebSocket • Safari 5+ Gateway • Firefox 4+ • socket.io • Opera 10.7+ • SockJS • Internet Explorer 10+ • web-socket.js (Flash) http://caniuse.com/#search=W ebSocket 34 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 35. 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 • Nowjs • PHP Websocket (.NET) • SockJS • websockify • Anaida (.NET) • SuperWebSocket • ActiveMQ • WebSocket Sharp (.NET) • • HornetMQ Jetty • Silverlight WebSocket client • phpwebsocket • Atmosphere • Java WebSocket Client • Protocol::WebSocket • APE Project • Arduino C++ WebSocket • em-websocket client • Xsockets • Jwebsocket • Ruby-web-socket • Orbited • WaterSprout Server • ZTWebSocket (Objective- • Atmosphere • Pywebsocket C) • Autobahn • And more… • Libwebsockets (C) • CouchDB • Netty 35 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 36. WebSocket Emulation • Kaazing WebSocket Gateway • http://www.kaazing.com/download • Makes WebSocket work in all browsers today (including I.E. 6) • Flash WebSocket implementation • http://github.com/gimite/web-socket-js • Requires opening port on the server's firewall • Socket.io • http://socket.io • Alternate API • Adds heartbeat, timeouts and disconnection • Uses Flash when available 36 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 37. Debugging in Chrome 37 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 38. Debugging in Chrome 38 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 39. Lab Preview WebSocket Basics Ingredients: • WebSocket-aware browser (Latest Chrome, Firefox) • Python-based server (localhost or cloud) • Web page w/ Javascript Steps: • Edit the page to check for browser support • Add form handler to send messages to server • See WebSockets in action! 39 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 40. Lab: WebSocket Basics 40 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 41. THE WEBSOCKET PROTOCOL 41 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 42. 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 42 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 43. WebSocket Handshake 43 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 44. WebSocket Frames • Have a few header bytes • Text or binary data • Frames are maskedfrom client to server 44 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 45. WebSocket Frames Wireshark Trace of WebSocket Basics Lab Message (Client to Server) FIN bit, MASK RSV bits, bit, payload mask payload Op-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 45 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 46. WebSocket Frames Wireshark Trace of WebSocket Basics Lab Message (Server to Client) FIN bit, MASK RSV bits, bit, payload payload Op-Code length 81 05 48 65 6C 6C 6F H e l l o 46 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 47. 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 47 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 48. WebSocket Framing Analysis Client Overhead Bytes Overhead Mbps 1,000 2,000 ~0.015* 10,000 20,000 ~0.153 100,000 200,000 ~1.526 * 2,000 bytes = 16,000 bits (~0.015 Mbps) 48 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 49. Polling vs. WebSocket 49 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 50. Latency Reduction 50 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 51. WebSocket Benchmark Using Comet Using WebSocket http://webtide.intalio.com/2011/09/cometd-2-4-0-websocket-benchmarks/ 51 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 52. WebSocket Summary • Extends network applications across the web • Desktop apps • Browser-based apps • Mobile apps • Far more efficient than HTTP • Part of the HTML5 Standard • Older browsers can play too 52 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 53. Bonus Lab: Network Traffic Analysis 53 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 54. PROTOCOL COMMUNICATION 54 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED Photo credit: zbigphotography
  • 55. Using WebSocket… • Extends legacy systems to the web • Message brokers, databases, etc. • Extends client-server protocols to the web: • XMPP, Jabber • Pub/Sub (Stomp/AMQP) • Gaming protocols • Any TCP-based protocol • RFB/VNC • Your browser becomes a first-class network citizen 55 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 56. Traditional Architecture 56 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 57. WebSocket Architecture 100% Hipster 57 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 58. “Why?” • Better responsiveness • Better scalability • Less traffic on the wire • Less work for the server • Easier back-end development • Custom commands = better match to your needs • Easier migration of existing systems • Just a new UI 58 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 59. Protocols • XMPP • STOMP • More… 59 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 60. XMPP • XMPP (Extensible Messaging and Presence Protocol) • Open XML technology for presence and real-time communication • Developed by the Jabber community in 1999 • Formalized by the IETF in 2002-2004 • Uses • Real-time chat • Client-Server • Examples: Google Talk, iChat, Facebook 60 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 61. XMPP XML XML <?xml version='1.0'?> Client  Server <stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'> <?xml version='1.0'?> <stream:stream Server Client from='example.com' plus encryption, authenticat id='someid' ion, and resource xmlns='jabber:client' binding xmlns:stream='http://etherx.jabber.org/streams' version='1.0'> 61 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 62. XMPP Conversation XML <?xml version='1.0'?> Client  Server <message from='rocky@example.com' to='sean@example.com' xml:lang='en'> <body>Hi Sean!</body> </message> <?xml version='1.0'?> <message from='sean@example.com' Server Client to='rocky@kaazing.com' xml:lang='en'> <body>Hi Rocky!</body> </message> 62 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 63. XMPP Command Set • Connect / disconnect • Register • Check roster • Sendmessages • Set status • Communicatepresence • + extensions 63 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 64. XMPP over WebSocket draft-moffitt-xmpp-over-websocket-00 Proposed protocol: • Add xmpp to Sec-WebSocket-Protocol header • Commands: regular XMPP XML • Stanzas: 1 per WebSocket frame • Keepalive: WebSocket PING command • Shutdown: • Close XMPP stream normally • Close WebSocket connection 64 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 65. Google Talk • Google Talk • Encrypted (XMPP over TLS) • Integrates w/ any service provider using XMPP • Hosted at talk.google.com on port 5222 • Authenticationthrough SASL PLAIN • example: http://kaazing.me 65 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 66. MESSAGE BROKERS AND STOMP 66 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 67. STOMP stomp.github.com • Streaming Text Oriented Messaging Protocol • Simple, easily-implemented protocol for use with message brokers • Provides an interoperable wire format • STOMP clients can communicate w/ almost every available message broker 67 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 68. Apache ActiveMQ • Open source message broker and JMS provider • Provides a publish-subscribe model based on JMS (Java Message Service) specification • Includes built-in support for STOMP 68 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 69. STOMP and WebSocket • Direct link between STOMP + WebSocket Providers stomp-websocket the browser & JMS Stomple broker Apache ActiveMQ • Radically simplified TorqueBox (Ruby) application design Kaazing Web Gateway JMS edition 69 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 70. STOMP Protocol Specification @ Github Message Structure Client Server • Frame-based Commands Responses ABORT ERROR • Request-response ACK MESSAGE • Heartbeat optional BEGIN RECEIPT COMMIT COMMAND CONNECT header1:value1 DISCONNECT header2:value2 SEND SUBSCRIBE Body^@ UNSUBSCRIBE 70 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 71. Lab Preview Protocol Libraries 71 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 72. Lab Preview Protocol Libraries Ingredients: • Safari 5.0+ Browser • Others not guaranteed • Apache web server (httpd) • Pre-installed on OS X, Windows installer provided • Apache ActiveMQ (localhost or cloud) • IMPORTANT: Add stomp and websocket transport connectors • Stock data source • Starter files • stomp-websocket library • HTML & CSS starters 72 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 73. Lab: Protocol Libraries 73 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 74. WEBSOCKETS IN THE REAL WORLD 74 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 75. Security 75 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 76. Security • Components of secure communication : 1. Transport Layer 2. Authentication 3. Authorization 4. Origin-BasedSecurity and CORS 76 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 77. Transport Layer Security (TLS) • Also known as SSL (Secure Socket Layer) support • HTTP over TLS is called HTTPS o Default port is 443 o HTTPS is not a separate protocol o An HTTPS connection is established after a successful TLS handshake (using public and private key certificates) 77 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 78. ws:// and wss:// schemes 78 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 79. Authentication • Mechanism by which systems identify users and check whether users really are who they represent themselves to be • Authentication process Step 1) Server issues a challenge using the HTTP 401 Authorization Requiredcode Step 2) Client responds by providing the requested authentication information if it can 79 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 80. Authorization • Mechanism by which a system determines users’ level of access o For example, a web page can have viewer, moderator, and administrator privileges • Access rights are typically stored in the policy store that is associated with the application 80 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 81. Web Origin Concept • Web Origin Concept RFC 6454: http://www.ietf.org/rfc/rfc6454.txt • An Origin is a subset of an address used for modeling trust relationships on the web • Origins consist of a scheme, a host, and a port: • Scheme: http:, https:, ws:, wss: • Host: www.example.com, img.example.com, 192.0.2.10 • Port: 80, 443 81 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 82. Same-Origin Policy “Generally speaking, documents retrieved from distinct origins are isolated from each other” – W3C http://www.w3.org/Security/wiki/Same_Origin_Policy • Browsers prevent a script or document loaded from one origin from communicating with a document loaded from another origin • Original security model for HTML • Introduced in Netscape Navigator 2.0 • Too limiting in this age of client-side web apps 82 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 83. Origin Quiz Which URLs have the same Origin? 1. http://www.example.com/index.html 2. https://www.example.com/index.html 3. http://img.example.com/html5.png 4. http://www.example.com:8080/page2.html 5. http://192.0.2.10:80/index.html* 6. http://www.example.com/about.html * Where 192.0.2.10 resolves to www.example.com 83 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 84. CORS enable-cors.org 84 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 85. Cross-Origin Requests • Have an Originheader • Contains the request’s origin • Produced by the browser • Cannot be changed by application code • Differs from referer[sic]: refereris a complete URL (can include full path) • Originating page’s server must approve (Access-Control-Allow-* headers) 85 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 86. CORS 86 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 87. Intermediaries 87 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 88. Types of Proxy Servers http://www.infoq.com/articles/Web-Sockets-Proxy-Servers 88 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 89. Proxy Servers • WebSocket protocol is unaware of proxy servers and firewalls • HTTP-based handshake Proxy type Connection Outcome Explicit Unencrypted 1. HTTP CONNECT 2.WebSocket connection flows to Explicit Encrypted destination Transparent Unencrypted Proxy strips extra headers, connection fails Transparent Encrypted Connection tunnels past proxy 89 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 90. Proxy Traversal Tree Case 2 Unencrypted Case 3 Encrypted WebSocket Connections WebSocket and Transparent Proxy Connections and Servers Explicit Proxy Servers Case 1 Unencrypted WebSocket Connections and Explicit Proxy Case 4 Encrypted Servers WebSocket Connections and Transparent Proxy Servers 90 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 91. Load Balancing Routers 1. TCP(layer-4) work well withWebSockets 2. HTTP (Layer 7) expect HTTP traffic, can get confused by WebSocket upgrade traffic. May need to be configured to be explicitly aware of WebSockettraffic. 91 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 92. Firewalls • Usually no specific WebSocketconcerns • Stateful packet inspection may need to know about WS protocol (or use WSS) 92 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 93. Twitter: @peterlubbers, @franksalim 93 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 94. Learn More… • HTML5 User Groups: • San Francisco: http://www.sfhtml5.org/ • Apress book: Pro HTML5 Programming • (Peter Lubbers, Brian Albers, & Frank Salim) http://www.prohtml5.com/ • Kaazing Corporation–Training: • http://kaazing.com/training/ 94 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 95. Questions and Answers 95 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 96. More HTML5 Code Labs! • Series of three Code Labs: • March 10 • April7 (Mobile with PPK) • May 5 (HTML Cinco! Geolocation) • In conjunction with GTUGSF • Sign up: http://GTUGsf.com/HTML5 96 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 97. Buy the Book! • Pro HTML5 Programming (Apress, 2011) • 50% off e-book coupon code: 50OFFHTML5 http://goo.gl/Dzq4A 97 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 98. Additional Resources • Scheme host port blog (Adam Barth): http://www.schemehostport.com/ • SPDY Essentials (Google Tech Talk): http://goo.gl/IcVdF • Breaking the Cross Domain Barrier (Alex Slexton): http://goo.gl/IcVdF • HTML5 Realtime and Connectivity video by Peter Lubbers: http://marakana.com/s/html_real-time,1066/index.html • XHR Level 2 Article (Eric Bidelman): http://www.html5rocks.com/en/tutorials/file/xhr2/ • HTML5 Weekly: http://html5weekly.com/ • The Web Ahead Podcasts: http://5by5.tv/webahead/ 98 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 99. Get Trained!  Proven, practical worldwide HTML5 Training (from experts, not just trainers): • E-mail us: training@kaazing.com • Web site: http://kaazing.com/training/ 99 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 100. - 100 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED
  • 101. 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. 101 © 2011 – Kaazing Corporation ALL RIGHTS RESERVED

Notas del editor

  1. http://mrdoob.com/projects/multiuserpad/
  2. CollectdViewer plots the output of the collectd statistics collection dameon in the browser at a rate of 2x per second. Visithttp://bergmans.com/WebSocket/collectdViewer.htmlfor more information.
  3. Rawkets – Developed by Rob Hawkes (Mozilla)
  4. What WebSocket is really good for is real-time applications. You wouldn&apos;t necessarily use WebSockets for everything, but for real-time applications it has some real value. Imagine you want to have instant updates in your browser application. It&apos;s hard to get those instant updates in a scalable manner using existing techniques like Ajax or Comet. So WebSockets are good for all kinds of real-time activity, data, monitoring.Today everyone is under pressure to provide applications in the browser. Think about your browser usage: sometimes you open a tab in a browser and read a page, such as the news, and then you click a link which takes you to another page. You read that page, click another link, and so on. This is traditional browsing or surfing the web. But there is also another use case for browsers and that is applications. You open a tab in your browser and go to your Yahoo Mail or Gmail or whatever and you read some mails, send some mails, and so on. Now you&apos;re not surfing the web but doing something task-oriented. In fact you probably leave that tab open so you can return to it and check your mail over time. If it&apos;s a good email client, like Gmail it doesn&apos;t even have page refreshes but stays on the same page. Another example is banking. You open a new tab, go to your banking website and perform some tasks like checking your balance or transferring funds. When you&apos;re finished you close the tab (hopefully!). Again you&apos;re not surfing the web, but are doing something specific.This is like running traditional applications on a desktop. You open an application, do some work, then close it. Or some applications you probably leave open all day.Running applications in a browser has some nice advantages: users can run them from anywhere (home, work, mobile, overseas, etc). It also doesn&apos;t matter what the underlying operating system is. However there are also some barriers to creating applications for the browser. One of those is the GUI itself. This is why Flash (or Silverlight) is popular, because it allowed developers to create rich GUI interfaces which run in a browser. As you&apos;ve been learning over the last couple of days, this trend of running applications in a browser is starting to be addressed by HTML5 and the standards it encompasses.But a big barrier to creating real-time applications in a browser is the network communication. Right now the only option for your application to communicate with the backend server is to use HTTP. An exception to that is to use sockets in Flash or Silverlight, but that comes with its own problems such as not being able to traverse firewalls and proxies which explains why that&apos;s not prevalent. For many applications, using HTTP is fine. But HTTP has limitations -- which we&apos;ll see -- which means that for many real-time applications it is not fine.Different aspects of HTML5 address different needs for real-time applications. And it&apos;s the WebSocket standard that addresses the communication needs.
  5. Request/response drivenMust open two connections: one for upstream, one for downstream, but traffic can only flow in one direction at time (added latency)--Full-duplex communication is where data can travel in both directions simultaneously. A desktop application that communicates with a backend is typically full-duplex. HTTP is what is known as &quot;half duplex&quot;. It is request-response driven. That is, a client sends a request to the server, and the server then sends a response back to the client. Only then can the client send another request. (That is with a single TCP connection. A browser could open another TCP connection and therefore be doing HTTP requests in parallel, but now you have multiple TCP connections. Browsers do this.)HTTP can also be said to be bi-directional. A clients sends a request one way, and the server sends a request the other way, so data can travel in two (i.e. bi) directions. But it is not full-duplex. With a socket connection that is full duplex, a client can send multiple messages to a server while at the same time the server can send multiple messages to the client. There is no need to have to wait in a request-response fashion.
  6. So HTTP is not the optimal protocol for this kind of communication.In addition, every HTTP message comes with a set of headers on top of the actual data payload. This means every time you poll – &quot;Do you have a message for me?&quot;, &quot;Do you have a message for me?&quot; – it includes the HTTP headers, too. So that&apos;s additional stuff in addition to the payload.
  7. The Web was originally designed for this request-response and the way to get real-time data would you have to refresh over and over, many times. So the next thought was to build this refreshing in under the covers, and you can do that by using Ajax. Ajax is common today and with it you can communicate to the server and then update the page without a page refresh. To an end user it gives the appearance of a low-latency real time application.(Back to diagram) So if you have an HTTP request to ping the server, &quot;do you have some data?&quot;, and then process that and display that on the page.. You can do all that and it makes for a pretty dynamic looking page. You can do that once a second, even. The user wouldn&apos;t be any wiser. It would seem like a responsive application even though you&apos;re polling. But even though the user doesn&apos;t see it, the browser is still sending all of these messages constantly to the server so you can imagine the kind of traffic that&apos;s going over the wire.
  8. Three ways to request info: polling, long-polling, and streaming
  9. Never-ending request to the server. There’s no response.Very efficient but not legal HTTP – should be request/response (proxies/firewalls do expect this information to be long-lived, so it waits/buffers until it’s complete, which then causes problems)You can only make so many connections to one domain
  10. And when the server responds it also has the HTTP Response Headers. And this hasn&apos;t included any data yet. The data, remember, is the prices of the stock.In this example the overhead was 871 bytes. Sometimes it&apos;s lower but it can also go quite a bit higher. In the range of 1,000 bytes is common.
  11. Ian Hickson, the HTML5 spec lead, has an interesting quote. Because of the latency reduction and reduction in the number of bytes going over the wire – these are huge to Google who operate on a such a scale that any saving in network traffic is worthwhile. So this will probably guarantee that WebSocket has a prominent place in the future.Think of, for example Google Docs. If I&apos;m in a Google Doc and Bob is too, I can see changes as he&apos;s making them; almost character for character. Imagine what that looks like without WebSocket. You&apos;re polling and for every character a user types, that 1 byte requires nearly 1,000 bytes of header traffic. That just doesn&apos;t scale.So you can see that in lots of different areas, such as where you pay for your bandwidth, or mobile communication, cloud computing it suddenly becomes interesting to reduce your header throughput by 1000x.
  12. This is where WebSocket enters the picture. WebSocket is a new HTML5 API, but also it was clear that you couldn&apos;t necessarily just keep building on the same HTTP protocol. So WebSocket is also a new protocol as well.
  13. Does anyone know what WebSockets have to do with model trains? Ian Hickson, who works for Google, is the HTML5 spec lead – not just for WebSocket but for all of HTML5. He does this both in WHATWG and W3C. And he is a big fan of model trains and had been playing with them for a long time (since before the internet was invented). He wanted to be able to control a model train from a browser, but just wanted a TCP connection running his own protocol to connect to the train controller. But of course you can&apos;t open a full-duplex socket connection from a browser. So he started doing it with techniques, called things like Ajax or Comet, available at the time. Other names are &quot;long polling&quot; or &quot;hanging get.” But all of these techniques involved polling or querying the server for an update as well as translating text-based data to TCP-based data and overall it was an inefficient and painful process.So Ian added something called &quot;TCP Connection&quot; to the HTML5 spec. At that point Kaazing had been going for a year, and they were working on building a better Comet server. When they saw the &quot;TCP Connection&quot; in the spec, they realized it was what they needed: a socket connection in a browser. So almost from one day to the next they realized they could throw out what they&apos;d been doing and begin contributing to the spec. The bulk of WebSocket today comes out of the work of Kaazing, although it&apos;s now an open standard and driven by the community including the likes of Apple, Google, browser vendors, and so on.So if want to build a model train controller, it will now be much simpler with WebSockets. 
  14. So there is the WHATWG that first created these new ideas. Then things are proposed to put into the official HTML5 spec, under W3C. But protocols are typically handled by IETF (Internet Engineering Task Force). We are actively involved in IETF meetings about the protocol.WebSocket is a protocol that allows you to create a full-duplex text-based socket. I say text-based because that&apos;s what it does at the moment, but there&apos;s already work in the spec to make a binary socket connection. In fact at Kaazing we&apos;ve already implemented binary sockets. It&apos;s pretty easy to do if you have that WebSocket foundation. What&apos;s nice with WebSockets is that they are able to share ports with existing HTTP traffic. It starts out as an HTTP handshake and then upgrades the underlying TCP connection to WebSocket. The first thing in the handshake is where the client says to the server, do you speak WebSocket. The server says yes and agrees to upgrade to the WebSocket protocol.It&apos;s cross-domain capable so it implements the CORS spec. And this is already powerful by itself, letting you do things you couldn&apos;t do with Ajax or Comet.And because of this HTTP handshake it can run over port 80 which means you don&apos;t have to open separate ports in firewalls and proxies.
  15. You can use JavaScript to evaluate if the browser has native support for WebSocket using code like this.Demo: Open Chrome, Ctrl-Shift-J for console, and type &quot;window.WebSocket” The same thing in other browsers comes back blank or undefined indicating no native support.
  16. The WebSocket API is straightforward and simple to use.First you create a new WebSocket and you pass in the WebSocket URL using the WebSocket scheme (ws://).Then it&apos;s a matter of associating these listeners. It&apos;s similar to actual socket programming: you have a listener so you know when messages arrive and then you can process them. It&apos;s truly asynchronous; you don&apos;t know when you&apos;re going to get this message. You&apos;re not polling anymore, you just get messages when they arrive.You have a listener for onopen so that you can react once the connection is open. Similarly you have an onclose listener to take any actions you want when the connection is closed. The main one is the onmessage listener so you can react every time a message arrives.
  17. With WebSockets you can also send messages back to a server. This is the full-duplex part. You use the send() function and simply specify the message you want to send. It&apos;s very easy.A close() function is used to end the connection.
  18. Having all of those servers with WebSocket support is great but to use them, you need a browser that supports WebSocket. Today only the Google Chrome and Safari browsers do that. So what do you do for users who are using other browsers? In particular there are a lot of corporate environments that strictly control browsers and versions. There are a surprising number of companies that are still on IE6, particularly in the financial industries. You have little hope of getting them onto Chrome or Safari just so they can use WebSocket.The solution is emulation. One way is using Flash. Flash has a way that lets you open a socket. With Flash, though, for secure WebSocket connections you need to host what is called a policies file and to host that it needs to be on a different port which means opening a new port in the firewalls. This negates the whole point of running on port 80. And as we&apos;ll learn later, in an enterprise environment when you start having proxy servers in the middle, a lot of the WebSocket connections don&apos;t work anymore. To counter that you need secure WebSockets. So the Flash emulation is not a great solution. Also, remember, Flash doesn&apos;t work on the iPhone or iPad.At Kaazing we spent a lot of development effort getting client emulation right. It is plugin-free and completely transparent so a developer doesn&apos;t have to care if the browser supports WebSocket or not. When you use the Kaazing client libraries it introspects the browser. If it supports WebSocket then great, if not, we automatically fall back to emulation mode. As far as the developer is concerned they are using the same API and have no idea if the browser is using native WebSocket or not. In either case their application just works.And when emulation kicks in because you&apos;re using a browser that doesn&apos;t support WebSocket, the performance is almost as good as native WebSocket itself. So even in the fallback scenario of using emulation, you still get better performance and scalability that can be done by the best Ajax or Comet solution today. The Kaazing client emulation will work in all browsers, including the dreaded IE6, so you aren&apos;t forced to wait until browsers get around to implementing WebSocket natively in the browser.
  19. - 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
  20. This is what the handshake looks like. If you use the WebSocket API, this is what happens under the covers. It&apos;s normal HTTP, and in the first part, the GET, there is an &quot;upgrade&quot; 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.
  21. Once you have this WebSocket connection setup you can start sending WebSocket frames. Again, you don&apos;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 &quot;frame&quot; 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&apos;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.
  22. 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&apos;s always fixed at 2 bytes while HTTP is variable. So you&apos;re going from 871 bytes to 2, which is huge reduction in overhead.We didn&apos;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.
  23. 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.
  24. 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&apos;t have to wait for a request from the client.So you get 3x improvement in latency with WebSocket.
  25. 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.)
  26. Objective – to show how a real application can be developed using WebSockets.Distributed applications require sending messages between two or more entities. For large, complicated system, the use of existing message broker software can simplify message handling. A standard API, known as the Java Messaging Service (JMS) API has bee developed to provide a standard way for Java applications to interface with these brokers.Kaazing WebSocket Gateway provides JavaScript libraries to access JMS broker via WebSocket
  27. Client server programming for the web--So what can you do with WebSocket? WebSocket is really nice, you have a way to speak to a remote server using this full-duplex communication. And the remote server can be anything, any WebSocket endpoint – a message broker, a database, a chat server, a game server, a web server, etc.Look at a desktop client that uses a socket, what do you do? Do applications send data back-and-forth in raw TCP? No. TCP is the transport layer and you run more useful protocols on top of that. If you&apos;re talking to a web server you&apos;ll use HTTP, which runs on top of TCP. If you&apos;re talking to a chat server, you&apos;ll use XMPP, which runs on top of TCP. If you&apos;re talking to a database then you&apos;ll use JDBC (if you&apos;re in Java), which runs on top of TCP.So the most useful aspect of TCP is that you don&apos;t actually use TCP, but rather you use higher-level protocols on top of it.And WebSockets are sockets, for the web. You can pass data back-and-forth using raw WebSockets if you want. But the most useful aspect of WebSocket is that it allows you to run higher-level protocols on top of it. Remember why we are doing this in the first place: because we have some back-end system and we want to build browser-based applications that can communicate with it. But these back-end systems already have some protocol to talk to them. And now with WebSocket can you use that protocol directly from the browser.Here&apos;s another way to look at it. If you have a client talking to a server (the middle-tier server, in this case) they have to agree on a contract. That is, they need to both understand the same protocol. If the server is sending stock data such as &quot;ORCL: 23.45, MSFT: 18.63, IBM: 126.92,” then the client needs to be able to understand it so it can parse it. So you&apos;re effectively creating your own syntax or protocol.But there might be something out there for a variety of things you want to do. If I&apos;m building a chat application I can say that I&apos;m expecting my messages to look a certain way. But someone&apos;s done that already, it&apos;s called XMPP and it&apos;s been around a long time. Why not take advantage of protocols that are already created? This is what people do with socket programming. They don&apos;t send data out on raw TCP, but use these higher-level protocols (like HTTP, XMPP, etc.). WebSocket is like client-server for the web. While you can use WebSocket by itself to send data, the real value comes from being able to run higher-level protocols on top of it.There are protocols for publishing and subscribing, for gaming, and so on. With WebSocket you can extend any TCP-based protocol.Going to the Web was a big step forward in most regards, but it was a big step backward in others. But now the browser is a first-class network citizen. It&apos;s like a desktop application you might have on an intranet. I like how some other person put it: “With WebSocket, the Web just got an upgrade.”
  28. Point to demo – rememberwhen we logged into Google Chat and chatted in real time.
  29. Draw diagram on thewhiteboardthat shows ActiveMQ is the message broker and Stomp is the protocol thatletsyou talk to the server
  30. Required to prevent unwanted eavesdropping, man-in-the-middle attacks, and packet sniffingHTTPS is HTTP running on top of a TLS connection (default port is 443)
  31. If you want to be sure, use WebSocket Secure!
  32. DiagramBrowser (WS)  Load Balancer -&gt; WS Service