SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
Simone Bordet
                      1
sbordet@intalio.com
How to Build

  WebSocket

Web Applications


            Simone Bordet
                               2
         sbordet@intalio.com
Simone Bordet

Senior Engineer/Architect at Intalio/Webtide
   Support for Jetty and CometD open source projects


Open Source Contributor
   Jetty, CometD, MX4J, Foxtrot, LiveTribe, JBoss, Larex


JVM tuning expert

Working on Web Network Protocols
   HTTP, WebSocket, SPDY, etc.

                                 Simone Bordet
                                                            3
                              sbordet@intalio.com
Agenda

What is WebSocket

WebSocket Browser API

WebSocket Server API

Demo

Q&A


                            Simone Bordet
                                               4
                         sbordet@intalio.com
What is WebSocket ?




             Simone Bordet
                                5
          sbordet@intalio.com
WebSocket


WebSocket is the HTML 5 standard protocol for
 bidirectional web communication
   HTTP is always client-initiated
   Finally, standard server-push


Work began in 2009, ended in 2012
   Excruciatingly painful
   But at the end, a good standard protocol



                                  Simone Bordet
                                                     6
                               sbordet@intalio.com
WebSocket Protocol


The WebSocket protocol is made of 2 parts
   WebSocket upgrade
   WebSocket data exchange


WebSocket upgrade
   It's plain old HTTP with an “Upgrade” header
   WebSocket runs on port 80
   Could be a trouble for inspecting HTTP proxies that
    do not support WebSocket


                                 Simone Bordet
                                                          7
                              sbordet@intalio.com
WebSocket Upgrade
REQUEST
GET / HTTP/1.1
Host: localhost:8080
Origin: http://localhost:8080
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Key: SbdIETLKHQ1TNBLeZFZS0g==
Sec-WebSocket-Version: 13


RESPONSE
HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: y4yXRUolfnFfo3Jc5HFqRHNgx2A=

                                            Simone Bordet
                                                               8
                                         sbordet@intalio.com
WebSocket Protocol

WebSocket data exchange
  Sequence of WebSocket “frames”
      0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
    +-+-+-+-+-------+-+-------------+-------------------------------+
    |F|R|R|R| opcode|M| Payload len |     Extended payload length     |
    |I|S|S|S| (4) |A|        (7)     |             (16/64)            |
    |N|V|V|V|        |S|             |   (if payload len==126/127)    |
    | |1|2|3|        |K|             |                                |
    +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
    |      Extended payload length continued, if payload len == 127 |
    + - - - - - - - - - - - - - - - +-------------------------------+
    |                                |Masking-key, if MASK set to 1 |
    +-------------------------------+-------------------------------+
    | Masking-key (continued)        |          Payload Data          |
    +-------------------------------- - - - - - - - - - - - - - - - +
    :                      Payload Data continued ...                 :
    + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
    |                      Payload Data continued                     |
    +---------------------------------------------------------------+

                                            Simone Bordet
                                                                          9
                                         sbordet@intalio.com
WebSocket Protocol

Very compact
   Smallest data frame has only 2 bytes overhead
Typical first byte is 0x81 for a text frame
   0x82 for a binary frame
   0x88 for a close frame
WebSocket “close” frame
   Sent by the application to signal end of data
   Must be replied before closing TCP connection
    Prevents loss of data
Browsers MUST mask frames
   But servers are not required to
                                 Simone Bordet
                                                    10
                              sbordet@intalio.com
WebSocket Performance




           Simone Bordet
                              11
        sbordet@intalio.com
WebSocket Performance




           Simone Bordet
                              12
        sbordet@intalio.com
WebSocket
Browser API




         Simone Bordet
                            13
      sbordet@intalio.com
WebSocket Browser API
interface WebSocket {
    WebSocket(DOMString url, optional (DOMString or DOMString[]) protocols)]

     attribute   Function?   onopen;
     attribute   Function?   onerror;
     attribute   Function?   onclose;
     attribute   Function?   onmessage;

     void send(DOMString data);
     void close(optional unsigned short code, optional DOMString reason);

     attribute DOMString binaryType; // “blob” or “arraybuffer”
     void send(ArrayBuffer data);
     void send(Blob data);
};


                                              Simone Bordet
                                                                               14
                                           sbordet@intalio.com
WebSocket Browser API Usage
var ws = new window.WebSocket(“ws://localhost:8080/ws”);
ws.send(“Hello, World”);


ws.onopen = function() {
     ws.send(“Hello, World”);
};
ws.onclose = function(event) {
     // Server closed
}
ws.onmessage = function(event) {
     var data = event.data;
     window.console.info(“Server says: ” + data);
};


                                             Simone Bordet
                                                                15
                                          sbordet@intalio.com
WebSocket
Server API




         Simone Bordet
                            16
      sbordet@intalio.com
WebSocket Server API


No standard API for WebSocket webapps yet

Servlet 3.0 addressed asynchronous HTTP
Servlet 3.1 (JSR 340) to address this
   Expected Q1 2013


For now, rely on Jetty API
   Java API for both client and server



                                  Simone Bordet
                                                     17
                               sbordet@intalio.com
WebSocket Jetty API
public class MyWebSocketServlet extends WebSocketServlet {
    public WebSocket doWebSocketConnect(HttpServletRequest r, String p) {
        return new MyWebSocket();
    }
}


public class MyWebSocket implements WebSocket.OnTextMessage {
    public void onOpen(Connection connection) {
    }
    public void onMessage(String data) {
    }
    public void onClose(int closeCode, String message) {
    }
}

                                              Simone Bordet
                                                                            18
                                           sbordet@intalio.com
Simone Bordet
                      19
sbordet@intalio.com
Conclusions


WebSocket programming is easy !

However, may not be widely deployed
   Old browsers
   Old internet proxies


WebSocket is low-level
   A framework on top gives much more productivity
   CometD

                                 Simone Bordet
                                                      20
                              sbordet@intalio.com
References

WebSocket Protocol
   http://www.ietf.org/rfc/rfc6455.txt
JSR 340 (Servlet 3.1)
   http://jcp.org/en/jsr/detail?id=340
WebSocket API
   http://dev.w3.org/html5/websockets/
Jetty
   http://eclipse.org/jetty
CometD
   http://cometd.org


                                    Simone Bordet
                                                       21
                                 sbordet@intalio.com
Questions
    &
 Answers




        Simone Bordet
                           22
     sbordet@intalio.com

Más contenido relacionado

La actualidad más candente

Websockets at tossug
Websockets at tossugWebsockets at tossug
Websockets at tossug
clkao
 
Setting mikrotik untuk game online campur browsing
Setting mikrotik untuk game online campur browsingSetting mikrotik untuk game online campur browsing
Setting mikrotik untuk game online campur browsing
imanariepin24
 
Ukk tkj p1 proxy mikrotik2014 2015
Ukk tkj p1 proxy mikrotik2014 2015Ukk tkj p1 proxy mikrotik2014 2015
Ukk tkj p1 proxy mikrotik2014 2015
Riza Hafizhuddin
 
Tola.leng mail server (sq_mail & rcmail)_q5_
Tola.leng mail server (sq_mail & rcmail)_q5_Tola.leng mail server (sq_mail & rcmail)_q5_
Tola.leng mail server (sq_mail & rcmail)_q5_
Tola LENG
 

La actualidad más candente (19)

Jetty Continuation - 이상민
Jetty Continuation - 이상민Jetty Continuation - 이상민
Jetty Continuation - 이상민
 
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
 
Web sockets
Web socketsWeb sockets
Web sockets
 
Websockets at tossug
Websockets at tossugWebsockets at tossug
Websockets at tossug
 
Basic command to configure mikrotik
Basic command to configure mikrotikBasic command to configure mikrotik
Basic command to configure mikrotik
 
Servlet 3.1 Async I/O
Servlet 3.1 Async I/OServlet 3.1 Async I/O
Servlet 3.1 Async I/O
 
Intro to WebSockets
Intro to WebSocketsIntro to WebSockets
Intro to WebSockets
 
Going Live! with Comet
Going Live! with CometGoing Live! with Comet
Going Live! with Comet
 
Time for Comet?
Time for Comet?Time for Comet?
Time for Comet?
 
Building Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsBuilding Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSockets
 
Setting mikrotik untuk game online campur browsing
Setting mikrotik untuk game online campur browsingSetting mikrotik untuk game online campur browsing
Setting mikrotik untuk game online campur browsing
 
Ukk tkj p1 proxy mikrotik2014 2015
Ukk tkj p1 proxy mikrotik2014 2015Ukk tkj p1 proxy mikrotik2014 2015
Ukk tkj p1 proxy mikrotik2014 2015
 
Instalasaun ubuntu 12+ subsonic
Instalasaun ubuntu 12+ subsonicInstalasaun ubuntu 12+ subsonic
Instalasaun ubuntu 12+ subsonic
 
Tola.leng mail server (sq_mail & rcmail)_q5_
Tola.leng mail server (sq_mail & rcmail)_q5_Tola.leng mail server (sq_mail & rcmail)_q5_
Tola.leng mail server (sq_mail & rcmail)_q5_
 
Basic work
Basic workBasic work
Basic work
 
Open vpn server_linux
Open vpn server_linuxOpen vpn server_linux
Open vpn server_linux
 
Restfs internals
Restfs internalsRestfs internals
Restfs internals
 
Ad, dns, dhcp, file server
Ad, dns, dhcp, file serverAd, dns, dhcp, file server
Ad, dns, dhcp, file server
 
Cometdの紹介
Cometdの紹介Cometdの紹介
Cometdの紹介
 

Destacado

Destacado (7)

DevNexus 2013 - Introduction to WebSockets
DevNexus 2013 - Introduction to WebSocketsDevNexus 2013 - Introduction to WebSockets
DevNexus 2013 - Introduction to WebSockets
 
Tech
TechTech
Tech
 
WebSocket Protocol と Plack::Middleware::WebSocket
WebSocket Protocol と Plack::Middleware::WebSocketWebSocket Protocol と Plack::Middleware::WebSocket
WebSocket Protocol と Plack::Middleware::WebSocket
 
Introduction to WebRTC
Introduction to WebRTCIntroduction to WebRTC
Introduction to WebRTC
 
Implementation Lessons using WebRTC in Asterisk
Implementation Lessons using WebRTC in AsteriskImplementation Lessons using WebRTC in Asterisk
Implementation Lessons using WebRTC in Asterisk
 
Prismic
PrismicPrismic
Prismic
 
Real-Time applications avec la spécification Java (JSR 356) et le protocole W...
Real-Time applications avec la spécification Java (JSR 356) et le protocole W...Real-Time applications avec la spécification Java (JSR 356) et le protocole W...
Real-Time applications avec la spécification Java (JSR 356) et le protocole W...
 

Similar a Realizzare applicazioni Web con WebSocket, by Simone Bordet

WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
Viktor Gamov
 
Dev con kolkata 2012 websockets
Dev con kolkata 2012   websocketsDev con kolkata 2012   websockets
Dev con kolkata 2012 websockets
SANKARSAN BOSE
 
Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010
sullis
 
Westhawk integration
Westhawk integrationWesthawk integration
Westhawk integration
Tim Panton
 

Similar a Realizzare applicazioni Web con WebSocket, by Simone Bordet (20)

Jetty 9 – The Next Generation Servlet Container
Jetty 9 – The Next Generation Servlet ContainerJetty 9 – The Next Generation Servlet Container
Jetty 9 – The Next Generation Servlet Container
 
HTTP, WebSocket, SPDY: evoluzione dei protocolli web by Simone Bordet
HTTP, WebSocket, SPDY: evoluzione dei protocolli web by Simone BordetHTTP, WebSocket, SPDY: evoluzione dei protocolli web by Simone Bordet
HTTP, WebSocket, SPDY: evoluzione dei protocolli web by Simone Bordet
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
 
Dev con kolkata 2012 websockets
Dev con kolkata 2012   websocketsDev con kolkata 2012   websockets
Dev con kolkata 2012 websockets
 
WebSockets On Fire
WebSockets On FireWebSockets On Fire
WebSockets On Fire
 
WebSocket Server - Jul 2010
WebSocket Server - Jul 2010WebSocket Server - Jul 2010
WebSocket Server - Jul 2010
 
Websocket shanon
Websocket shanonWebsocket shanon
Websocket shanon
 
[workshop] The Revolutionary WebRTC
[workshop] The Revolutionary WebRTC[workshop] The Revolutionary WebRTC
[workshop] The Revolutionary WebRTC
 
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
 
Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010
 
Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile Web
 
Spring + WebSocket integration
Spring + WebSocket integrationSpring + WebSocket integration
Spring + WebSocket integration
 
Introduction to Reactive Streams: Current & Future - Simone Bordet - Codemoti...
Introduction to Reactive Streams: Current & Future - Simone Bordet - Codemoti...Introduction to Reactive Streams: Current & Future - Simone Bordet - Codemoti...
Introduction to Reactive Streams: Current & Future - Simone Bordet - Codemoti...
 
Jwebsocketmobiletechcon2010en 100912071225 Phpapp01
Jwebsocketmobiletechcon2010en 100912071225 Phpapp01Jwebsocketmobiletechcon2010en 100912071225 Phpapp01
Jwebsocketmobiletechcon2010en 100912071225 Phpapp01
 
jWebSocket MobileTechCon 2010 - WebSockets on Android, Symbian and BlackBerry
jWebSocket MobileTechCon 2010 - WebSockets on Android, Symbian and BlackBerryjWebSocket MobileTechCon 2010 - WebSockets on Android, Symbian and BlackBerry
jWebSocket MobileTechCon 2010 - WebSockets on Android, Symbian and BlackBerry
 
110828recruit agent ws
110828recruit agent ws110828recruit agent ws
110828recruit agent ws
 
Enhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocketEnhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocket
 
Websockets en Ruby en 5 Minutos
Websockets en Ruby en 5 MinutosWebsockets en Ruby en 5 Minutos
Websockets en Ruby en 5 Minutos
 
Ws
WsWs
Ws
 
Westhawk integration
Westhawk integrationWesthawk integration
Westhawk integration
 

Más de Codemotion

Más de Codemotion (20)

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending story
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storia
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard Altwasser
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Realizzare applicazioni Web con WebSocket, by Simone Bordet

  • 1. Simone Bordet 1 sbordet@intalio.com
  • 2. How to Build WebSocket Web Applications Simone Bordet 2 sbordet@intalio.com
  • 3. Simone Bordet Senior Engineer/Architect at Intalio/Webtide  Support for Jetty and CometD open source projects Open Source Contributor  Jetty, CometD, MX4J, Foxtrot, LiveTribe, JBoss, Larex JVM tuning expert Working on Web Network Protocols  HTTP, WebSocket, SPDY, etc. Simone Bordet 3 sbordet@intalio.com
  • 4. Agenda What is WebSocket WebSocket Browser API WebSocket Server API Demo Q&A Simone Bordet 4 sbordet@intalio.com
  • 5. What is WebSocket ? Simone Bordet 5 sbordet@intalio.com
  • 6. WebSocket WebSocket is the HTML 5 standard protocol for bidirectional web communication  HTTP is always client-initiated  Finally, standard server-push Work began in 2009, ended in 2012  Excruciatingly painful  But at the end, a good standard protocol Simone Bordet 6 sbordet@intalio.com
  • 7. WebSocket Protocol The WebSocket protocol is made of 2 parts  WebSocket upgrade  WebSocket data exchange WebSocket upgrade  It's plain old HTTP with an “Upgrade” header  WebSocket runs on port 80  Could be a trouble for inspecting HTTP proxies that do not support WebSocket Simone Bordet 7 sbordet@intalio.com
  • 8. WebSocket Upgrade REQUEST GET / HTTP/1.1 Host: localhost:8080 Origin: http://localhost:8080 Connection: Upgrade Upgrade: websocket Sec-WebSocket-Key: SbdIETLKHQ1TNBLeZFZS0g== Sec-WebSocket-Version: 13 RESPONSE HTTP/1.1 101 Switching Protocols Connection: Upgrade Upgrade: websocket Sec-WebSocket-Accept: y4yXRUolfnFfo3Jc5HFqRHNgx2A= Simone Bordet 8 sbordet@intalio.com
  • 9. WebSocket Protocol WebSocket data exchange  Sequence of WebSocket “frames” 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 +-+-+-+-+-------+-+-------------+-------------------------------+ |F|R|R|R| opcode|M| Payload len | Extended payload length | |I|S|S|S| (4) |A| (7) | (16/64) | |N|V|V|V| |S| | (if payload len==126/127) | | |1|2|3| |K| | | +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - + | Extended payload length continued, if payload len == 127 | + - - - - - - - - - - - - - - - +-------------------------------+ | |Masking-key, if MASK set to 1 | +-------------------------------+-------------------------------+ | Masking-key (continued) | Payload Data | +-------------------------------- - - - - - - - - - - - - - - - + : Payload Data continued ... : + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | Payload Data continued | +---------------------------------------------------------------+ Simone Bordet 9 sbordet@intalio.com
  • 10. WebSocket Protocol Very compact  Smallest data frame has only 2 bytes overhead Typical first byte is 0x81 for a text frame  0x82 for a binary frame  0x88 for a close frame WebSocket “close” frame  Sent by the application to signal end of data  Must be replied before closing TCP connection Prevents loss of data Browsers MUST mask frames  But servers are not required to Simone Bordet 10 sbordet@intalio.com
  • 11. WebSocket Performance Simone Bordet 11 sbordet@intalio.com
  • 12. WebSocket Performance Simone Bordet 12 sbordet@intalio.com
  • 13. WebSocket Browser API Simone Bordet 13 sbordet@intalio.com
  • 14. WebSocket Browser API interface WebSocket { WebSocket(DOMString url, optional (DOMString or DOMString[]) protocols)] attribute Function? onopen; attribute Function? onerror; attribute Function? onclose; attribute Function? onmessage; void send(DOMString data); void close(optional unsigned short code, optional DOMString reason); attribute DOMString binaryType; // “blob” or “arraybuffer” void send(ArrayBuffer data); void send(Blob data); }; Simone Bordet 14 sbordet@intalio.com
  • 15. WebSocket Browser API Usage var ws = new window.WebSocket(“ws://localhost:8080/ws”); ws.send(“Hello, World”); ws.onopen = function() { ws.send(“Hello, World”); }; ws.onclose = function(event) { // Server closed } ws.onmessage = function(event) { var data = event.data; window.console.info(“Server says: ” + data); }; Simone Bordet 15 sbordet@intalio.com
  • 16. WebSocket Server API Simone Bordet 16 sbordet@intalio.com
  • 17. WebSocket Server API No standard API for WebSocket webapps yet Servlet 3.0 addressed asynchronous HTTP Servlet 3.1 (JSR 340) to address this  Expected Q1 2013 For now, rely on Jetty API  Java API for both client and server Simone Bordet 17 sbordet@intalio.com
  • 18. WebSocket Jetty API public class MyWebSocketServlet extends WebSocketServlet { public WebSocket doWebSocketConnect(HttpServletRequest r, String p) { return new MyWebSocket(); } } public class MyWebSocket implements WebSocket.OnTextMessage { public void onOpen(Connection connection) { } public void onMessage(String data) { } public void onClose(int closeCode, String message) { } } Simone Bordet 18 sbordet@intalio.com
  • 19. Simone Bordet 19 sbordet@intalio.com
  • 20. Conclusions WebSocket programming is easy ! However, may not be widely deployed  Old browsers  Old internet proxies WebSocket is low-level  A framework on top gives much more productivity  CometD Simone Bordet 20 sbordet@intalio.com
  • 21. References WebSocket Protocol  http://www.ietf.org/rfc/rfc6455.txt JSR 340 (Servlet 3.1)  http://jcp.org/en/jsr/detail?id=340 WebSocket API  http://dev.w3.org/html5/websockets/ Jetty  http://eclipse.org/jetty CometD  http://cometd.org Simone Bordet 21 sbordet@intalio.com
  • 22. Questions & Answers Simone Bordet 22 sbordet@intalio.com