SlideShare a Scribd company logo
Yet another html5j meetup on July 5th, 2012




WEBSOCKET PROTOCOL


                          http://goo.gl/0kJGW
2012/7/5(THU)
KENSAKU KOMATSU
SELF-INTRODUCTION
• Researching cutting-edge web technology
   • Especially APIs related to NW, in preference 



• Google API Expert (HTML5)
• Microsoft Most Valuable Professional(IE)


• Twitter: @komasshu
• Blog: http://blog.livedoor.jp/kotesaki
ACTIVITIES                   http://www.html5rocks.com/en/tutorials/speed/quick/


(I LOVE SPEED!!)




                                      Referred!!, But… orz
                                      (I know I should do feedback)




          http://wakachi.komasshu.info/
TODAY’S MAIN IDEA

Two topics


1. Introduction to WebSocket and
   SPDY


2. Dive into WebSocket Protocol.
http://www.flickr.com/photos/cubedude27/4892016155/




TOPIC1:




Introduction to WebSocket and
SPDY
EVOLVINGOF
    WEB SERVICES
1991                                                                                             2012
http://www.ibarakiken.gr.jp/www/index.html   http://www.ocn.ne.jp/   https://www.facebook.com/
COMMUNICATION MODEL
    HAS BEEN CHANGED
1991                                                                                               2012
http://www.ibarakiken.gr.jp/www/index.html     http://www.ocn.ne.jp/   https://www.facebook.com/




                                                                         Multiple resources
        Single resource                                                           +
                                             Multiple resources            Bi-directional
TRANSPORT
PROTOCOLHAS NOT
CHANGED


REQUEST   GET index.html

                           RESPONSE

REQUEST   GET style.css

                           RESPONSE
ISSUESINHTTP
Slowinmultiple resources   Periodically polling




                                                   hello!




                                         “hello”
CURRENT PRACTICE
FOR SOLVING ISSUES
Concurrent tcp connections   Long Polling




                                                      hello!



                                            “hello”
BUT STILL…
• Concurrent tcp request
  • Increase server load
  • Heavy loadto intermediary
      • e.g. NAT, proxy, FireWall…
• Long polling
  • Complicated coding
  • Increase traffics
      • Header: k – 10k order
      • Payload : 10 bytes order …
CUTTING EDGE
PROTOCOLS
SPDY, WEBSOCKET
SPDY                    WebSocket




                           ・Enable bidirectional
                            communication wo/
                                restrictions.
                           (request not needed)
                           ・Header overhead is     hello!
                              extremely small.
   ・Multiplex request
   Under single https                 “hello”
     connection.
PROTOCOL STACKS


                     SPDY              WebSocket
                 SPDY (HTTP layer)      Any protocols

                SPDY (framing layer)     WebSocket
                              TLS                  TLS

                        TCP                 TCP


SSBP will be applied here?
A COMPARATIVE
TABLE
               SPDY                         WebSocket
Goal           reduce the latency of web    provide two-way
               pages                        communication to browser-
                                            based application
How to setup   1. apply patch/module to     1. setup middleware
                  your middleware           2. write server side
                                               programming
                                            3. write client side javascript
Migration      very easy                    expensive
Coding skill   not required                mandatory
What we can    Fast while downloading web   Anything (especially bi-
serve?         resources.                   directional webapps (e.g.
                                            chat, push services, online
                                            game ))
TOPIC2:



 Dive into WebSocket Protocol




            http://www.flickr.com/photos/nektar/6085553520/sizes/z/in/photostream/
DEMO:MULTI DEVICE
                         WebIntents
                               +

INTERACTION
                       ServiceDiscovery
                            (uPnP)




                    WebSocket
DEMO: COMPARATIVE
TEST (WS VS HTTP)




    http://refws.komasshu.info/echocompare.html
REF: CASE HTTP
// send request
$.get(“http://example.com”, function(data, e) {
// when data is received
console.log(data);
});




                              To receive data, sending request must be
                                              required.
HOW TO USE WEBSOCKET?
(BROWSER SIDE API)
// initiate connection
varws = new WebSocket(“ws://example.com/”);
// right after connection established
ws.onconnect = function(e) { ... };
// when data arrival from server
ws.onmessage = function(e) { console.log(e.data); }
// send data to server
ws.send(“hello”);
// close connection
ws.close();
                                sending and receiving data works
                                         independently.
PROTOCOL OVERVIEW
The WebSocketProtocol (RFC6455)


•Has two parts
  • handshake
       • in context of HTTP/1.1
  • data transfer
       • frame format
•protocol schema
  • ws (80), wss(443)
•browsers
  • chrome, firefox, safari, opera(need configuration), IE10
  • iOS safari, Android browser (Chrome)
SEQUENCE OVERVIEW


          handshake



         data transfer




            closing
HANDSHAKE
 client to server




                    server to client
DATA FRAMING
                     indicates text, binary, ping, pong, close ...




      Payload data is masked with Masking-key (XOR base)
      (preventing Firewall Circumvention & Cache Poisoning)
WHAT FOR
PING/PONG?
                Under no-traffic, intermediaries
                    release session table




                                              Load
                               Fire
                NAT                           Balan
                               Wall
                                               cer
 websocket
 connection

              Known as “silent close”.
WHAT FOR
  PING/PONG? [CONT]



                                      Load       ping
                             Fire
                   NAT                Balan
   pong                      Wall
                                       cer
     websocket
     connection



ping & pong is used to prevent silent close (Keep-alive)
ADDITIONAL INFO
 CGN IN MOBILE NW
CGN is already installed into almost all mobile career NW.
So using ping/pong is necessary (also thinking about battery issues).




                                 G

                        Career Grade NAT
                    P        P        P      P
                     IPv4 Private address NW
GETTING REACH
ABILITY
                Treat WS traffic as HTTP/1.1
               ⇨ Data framing will blocked ;-(




                                           Load
                              Fire
               proxy                       Balan
                              Wall
                                            cer
 websocket
 connection



         Use WSS (prevent interruption)
SUBPROTOCOL
•WebSocket can handle any data schema.
  • example: transfer mouse coordinates
        • option1 : {x: 1, y:240}
        • option2 : [1, 240]
        • option3 : {x: “1px”, y: “240px”}
  • ...... lack of interoperability


•subprotocol addresses the interoperability problem
  • define schema, sequence, ...
  • should register IANA
        • identifier, common name, definition
SUBPROTOCOL[CONT]




      http://www.iana.org/assignments/websocket/websocket.xml
EXTENSION
Two proposal are now discussed.


•Multiplexing Extension
  • http://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing-
    03

•Per-frame Compression
  • http://tools.ietf.org/html/draft-ietf-hybi-websocket-perframe-
    compression-04
SOCKET.IO
Automatically fallback from WebSocket to Comet.
Automatic keep-alive, name space, ... very convenient!!




                                           http://socket.io/
FOR SCALABLE
   SERVICES

                           redis, mongoDB, ...             sync status /
                                                          message sharing



             WS            WS           WS        WS
            server        server       server    server




node-proxy
                              Load balancer                some persistency
nginx(work in progress)
                                                              will required
                                                            (source IP hash,
                     user access                               cookie ...)
CONCLUSION
•WebSocket
 •   provide two-way communication to browser-based application
 •   NO request & response restrictions
 •   default port is 80 (ws), 443(wss)
 •   consists of two parts
         • handshake : upgrade mechanism
         • data transfer : text (utf-8) and binary
 • ping/pong
         • prevent silent close
 • wss
         • get reach ability
 • subprotocol
         • interoperability
 • extensions
         • multiplexing, per-frame compression
http://www.flickr.com/photos/23086934@N02/2250806050/

More Related Content

PPT
RIP - Routing Information Protocol
PPT
OSI Transport Layer
PDF
CapellaDays2022 | NavalGroup | Closing the gap between traditional engineerin...
PPTX
Youtube Transcript Sumariser- application of API
PPTX
Интернетке қосу және браузерлер түрі
PPTX
Intro lecture: Theory and method for media technology
PPTX
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
RIP - Routing Information Protocol
OSI Transport Layer
CapellaDays2022 | NavalGroup | Closing the gap between traditional engineerin...
Youtube Transcript Sumariser- application of API
Интернетке қосу және браузерлер түрі
Intro lecture: Theory and method for media technology
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)

Viewers also liked (6)

PPTX
Introduction to WebSockets
PDF
IoT - the Next Wave of DDoS Threat Landscape
PPT
Honeypot honeynet
PPT
DDoS Attacks
PDF
AWS初心者向けWebinar AWS上でのDDoS対策
PPTX
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
Introduction to WebSockets
IoT - the Next Wave of DDoS Threat Landscape
Honeypot honeynet
DDoS Attacks
AWS初心者向けWebinar AWS上でのDDoS対策
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
Ad

Similar to WebSocket protocol (20)

PDF
Introduction to WebSockets
KEY
The HTML5 WebSocket API
PDF
HTML5 WebSockets
PPTX
Building WebSocket and Server Side Events Applications using Atmosphere
PDF
DevCon 5 (July 2013) - WebSockets
PDF
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
PPTX
PPTX
WebSockets in JEE 7
PPTX
Codecamp Iasi-26 nov 2011 - Html 5 WebSockets
PPTX
Codecamp iasi-26 nov 2011-web sockets
PDF
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
KEY
Pushing the web — WebSockets
PDF
Intro to WebSockets and Comet
PDF
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
PPTX
Connected Web Systems
PDF
Websocket shanon
PPT
HTML5 WebSocket: The New Network Stack for the Web
PDF
Building Next Generation Real-Time Web Applications using Websockets
PPTX
V2 peter-lubbers-sf-jug-websocket
PDF
Real-Time with Flowdock
Introduction to WebSockets
The HTML5 WebSocket API
HTML5 WebSockets
Building WebSocket and Server Side Events Applications using Atmosphere
DevCon 5 (July 2013) - WebSockets
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets in JEE 7
Codecamp Iasi-26 nov 2011 - Html 5 WebSockets
Codecamp iasi-26 nov 2011-web sockets
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Pushing the web — WebSockets
Intro to WebSockets and Comet
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Connected Web Systems
Websocket shanon
HTML5 WebSocket: The New Network Stack for the Web
Building Next Generation Real-Time Web Applications using Websockets
V2 peter-lubbers-sf-jug-websocket
Real-Time with Flowdock
Ad

More from Kensaku Komatsu (20)

PPTX
Media processing with serverless architecture
PPTX
Boxdev lt-09082016
PPTX
a pattern for PWA, PRPL
PPTX
Full Matrix Auto Test Framework for WebRTC
PPTX
WebRTC 101
PDF
04122016 web rtc_globalsummit
PPTX
02172016 web rtc_conf_komasshu
PDF
SkyWay国内唯一のCPaaS
PDF
ラズパイでWebRTC ヾ(*´∀`*)ノキャッキャ uv4l-webrtc 軽くハックしてみたよ!
PDF
ビデオ通話・P2Pがコモディティ化する世界 WebRTCによるこれからを探る
PDF
最新Web 通信系API総まくり!WebRTC, Streams, Push api etc.
PPTX
FirefoxでgetStats()
PPT
14th apr2015 リックテレコ勉強会
PPTX
WebRTCが拓く 新たなWebビジネスの世界
PPTX
Web of Thingsの現状とWebRTC活用の可能性
PPTX
25th nov2014 52thhtml5j
PPTX
知ってると得するかもしれないConstraintsたち
PPTX
WebRTCにより可視化されるリアルタイムクラウド。求められるAPI
PPTX
エフサミ2014 web rtcの傾向と対策
PPTX
HTML5 Night 2014 Web x Network Technology ( WebRTC )
Media processing with serverless architecture
Boxdev lt-09082016
a pattern for PWA, PRPL
Full Matrix Auto Test Framework for WebRTC
WebRTC 101
04122016 web rtc_globalsummit
02172016 web rtc_conf_komasshu
SkyWay国内唯一のCPaaS
ラズパイでWebRTC ヾ(*´∀`*)ノキャッキャ uv4l-webrtc 軽くハックしてみたよ!
ビデオ通話・P2Pがコモディティ化する世界 WebRTCによるこれからを探る
最新Web 通信系API総まくり!WebRTC, Streams, Push api etc.
FirefoxでgetStats()
14th apr2015 リックテレコ勉強会
WebRTCが拓く 新たなWebビジネスの世界
Web of Thingsの現状とWebRTC活用の可能性
25th nov2014 52thhtml5j
知ってると得するかもしれないConstraintsたち
WebRTCにより可視化されるリアルタイムクラウド。求められるAPI
エフサミ2014 web rtcの傾向と対策
HTML5 Night 2014 Web x Network Technology ( WebRTC )

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
KodekX | Application Modernization Development
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
cuic standard and advanced reporting.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Cloud computing and distributed systems.
NewMind AI Monthly Chronicles - July 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Spectral efficient network and resource selection model in 5G networks
KodekX | Application Modernization Development
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
cuic standard and advanced reporting.pdf
Big Data Technologies - Introduction.pptx
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Building Integrated photovoltaic BIPV_UPV.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf

WebSocket protocol

  • 1. Yet another html5j meetup on July 5th, 2012 WEBSOCKET PROTOCOL http://goo.gl/0kJGW 2012/7/5(THU) KENSAKU KOMATSU
  • 2. SELF-INTRODUCTION • Researching cutting-edge web technology • Especially APIs related to NW, in preference  • Google API Expert (HTML5) • Microsoft Most Valuable Professional(IE) • Twitter: @komasshu • Blog: http://blog.livedoor.jp/kotesaki
  • 3. ACTIVITIES http://www.html5rocks.com/en/tutorials/speed/quick/ (I LOVE SPEED!!) Referred!!, But… orz (I know I should do feedback) http://wakachi.komasshu.info/
  • 4. TODAY’S MAIN IDEA Two topics 1. Introduction to WebSocket and SPDY 2. Dive into WebSocket Protocol.
  • 6. EVOLVINGOF WEB SERVICES 1991 2012 http://www.ibarakiken.gr.jp/www/index.html http://www.ocn.ne.jp/ https://www.facebook.com/
  • 7. COMMUNICATION MODEL HAS BEEN CHANGED 1991 2012 http://www.ibarakiken.gr.jp/www/index.html http://www.ocn.ne.jp/ https://www.facebook.com/ Multiple resources Single resource + Multiple resources Bi-directional
  • 8. TRANSPORT PROTOCOLHAS NOT CHANGED REQUEST GET index.html RESPONSE REQUEST GET style.css RESPONSE
  • 9. ISSUESINHTTP Slowinmultiple resources Periodically polling hello! “hello”
  • 10. CURRENT PRACTICE FOR SOLVING ISSUES Concurrent tcp connections Long Polling hello! “hello”
  • 11. BUT STILL… • Concurrent tcp request • Increase server load • Heavy loadto intermediary • e.g. NAT, proxy, FireWall… • Long polling • Complicated coding • Increase traffics • Header: k – 10k order • Payload : 10 bytes order …
  • 12. CUTTING EDGE PROTOCOLS SPDY, WEBSOCKET SPDY WebSocket ・Enable bidirectional communication wo/ restrictions. (request not needed) ・Header overhead is hello! extremely small. ・Multiplex request Under single https “hello” connection.
  • 13. PROTOCOL STACKS SPDY WebSocket SPDY (HTTP layer) Any protocols SPDY (framing layer) WebSocket TLS TLS TCP TCP SSBP will be applied here?
  • 14. A COMPARATIVE TABLE SPDY WebSocket Goal reduce the latency of web provide two-way pages communication to browser- based application How to setup 1. apply patch/module to 1. setup middleware your middleware 2. write server side programming 3. write client side javascript Migration very easy expensive Coding skill not required  mandatory What we can Fast while downloading web Anything (especially bi- serve? resources. directional webapps (e.g. chat, push services, online game ))
  • 15. TOPIC2: Dive into WebSocket Protocol http://www.flickr.com/photos/nektar/6085553520/sizes/z/in/photostream/
  • 16. DEMO:MULTI DEVICE WebIntents + INTERACTION ServiceDiscovery (uPnP) WebSocket
  • 17. DEMO: COMPARATIVE TEST (WS VS HTTP) http://refws.komasshu.info/echocompare.html
  • 18. REF: CASE HTTP // send request $.get(“http://example.com”, function(data, e) { // when data is received console.log(data); }); To receive data, sending request must be required.
  • 19. HOW TO USE WEBSOCKET? (BROWSER SIDE API) // initiate connection varws = new WebSocket(“ws://example.com/”); // right after connection established ws.onconnect = function(e) { ... }; // when data arrival from server ws.onmessage = function(e) { console.log(e.data); } // send data to server ws.send(“hello”); // close connection ws.close(); sending and receiving data works independently.
  • 20. PROTOCOL OVERVIEW The WebSocketProtocol (RFC6455) •Has two parts • handshake • in context of HTTP/1.1 • data transfer • frame format •protocol schema • ws (80), wss(443) •browsers • chrome, firefox, safari, opera(need configuration), IE10 • iOS safari, Android browser (Chrome)
  • 21. SEQUENCE OVERVIEW handshake data transfer closing
  • 22. HANDSHAKE client to server server to client
  • 23. DATA FRAMING indicates text, binary, ping, pong, close ... Payload data is masked with Masking-key (XOR base) (preventing Firewall Circumvention & Cache Poisoning)
  • 24. WHAT FOR PING/PONG? Under no-traffic, intermediaries release session table Load Fire NAT Balan Wall cer websocket connection Known as “silent close”.
  • 25. WHAT FOR PING/PONG? [CONT] Load ping Fire NAT Balan pong Wall cer websocket connection ping & pong is used to prevent silent close (Keep-alive)
  • 26. ADDITIONAL INFO CGN IN MOBILE NW CGN is already installed into almost all mobile career NW. So using ping/pong is necessary (also thinking about battery issues). G Career Grade NAT P P P P IPv4 Private address NW
  • 27. GETTING REACH ABILITY Treat WS traffic as HTTP/1.1 ⇨ Data framing will blocked ;-( Load Fire proxy Balan Wall cer websocket connection Use WSS (prevent interruption)
  • 28. SUBPROTOCOL •WebSocket can handle any data schema. • example: transfer mouse coordinates • option1 : {x: 1, y:240} • option2 : [1, 240] • option3 : {x: “1px”, y: “240px”} • ...... lack of interoperability •subprotocol addresses the interoperability problem • define schema, sequence, ... • should register IANA • identifier, common name, definition
  • 29. SUBPROTOCOL[CONT] http://www.iana.org/assignments/websocket/websocket.xml
  • 30. EXTENSION Two proposal are now discussed. •Multiplexing Extension • http://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing- 03 •Per-frame Compression • http://tools.ietf.org/html/draft-ietf-hybi-websocket-perframe- compression-04
  • 31. SOCKET.IO Automatically fallback from WebSocket to Comet. Automatic keep-alive, name space, ... very convenient!! http://socket.io/
  • 32. FOR SCALABLE SERVICES redis, mongoDB, ... sync status / message sharing WS WS WS WS server server server server node-proxy Load balancer some persistency nginx(work in progress) will required (source IP hash, user access cookie ...)
  • 33. CONCLUSION •WebSocket • provide two-way communication to browser-based application • NO request & response restrictions • default port is 80 (ws), 443(wss) • consists of two parts • handshake : upgrade mechanism • data transfer : text (utf-8) and binary • ping/pong • prevent silent close • wss • get reach ability • subprotocol • interoperability • extensions • multiplexing, per-frame compression