WEB SOCKETS CURRENT STATE FOR JAVA DEVELOPERS
Web SOCKETS CURRENT STATE FOR JAVA DEVELOPERS PRESENTED BY VIKTOR GAMOV
WEB SOCKETS AGENDA BIT OF MEET WEBSOCKETS Q&A HISTORY THE WEBSOCKETS IN ACTION SESSION ?
OPTIONS FOR “REALTIME” WEB “LEGACY” WEB POLLING LONG-POLLING STEAMING Browser sends HTTP requests at Browser sends a request to the regular intervals and server and the server keeps the Browser sends a complete immediately receives a request open for a set period request, but the server sends response. However, real- time of time. If a notification is and maintains an open data is often not that received within that period, a response that is continuously predictable, making response containing the updated and kept open unnecessary requests message is sent to the client. If indefinitely (or for a set period inevitable and as a result, a notification is not received of time) many connections are opened within the set time period, the and closed needlessly in low- server sends a response to message-rate situations terminate the open request.
WHAT IS WEBSOCKET “Reducing kilobytes of data to 2 bytes... and reducing latency from 150ms to 50 ms is far more than marginal. In fact, these two factors alone are enough to make WebSocket seriously interesting...” www.ietf.org/mail-archive/web/hybi/current/msg00784.html
WHAT IS WEBSOCKETS? WEB SOCKET STANDARD PROTOCOL CLIENT-SIDE API SERVER-SIDE API Websocket is a HTML5 specification True real-time server standardized technology introduces WebSocket updates. Expected large (described in RFC6455) client side object. No penetration in Java to support low-overhead plugin required. world with upcoming bidirectional traffic from JavaEE 7 spec and your Web browser. JSR-356
WEBSOCKET HANDSHAKE To Start full-duplex communication client should send UPGRADE request 1 2 3 4 SEND RECEIVE CHANGE LISTEN UPGRADE UPGRADE READYSTATE MESSAGE REQUEST RESPONSE TO OPEN EVENT
DEMO HANDSHAKE DEMO
WEBSOCKET INTERFACE [Constructor(DOMString  url,  optional  (DOMString  or  DOMString[])  protocols)] interface  WebSocket  :  EventTarget  {    readonly  attribute  DOMString  url;    //  ready  state    const  unsigned  short  CONNECTING  =  0;    const  unsigned  short  OPEN  =  1;    const  unsigned  short  CLOSING  =  2;    const  unsigned  short  CLOSED  =  3;    readonly  attribute  unsigned  short  readyState;    readonly  attribute  unsigned  long  bufferedAmount;    //  networking    [TreatNonCallableAsNull]  attribute  Function?  onopen;    [TreatNonCallableAsNull]  attribute  Function?  onerror;    [TreatNonCallableAsNull]  attribute  Function?  onclose;    readonly  attribute  DOMString  extensions;    readonly  attribute  DOMString  protocol;    void  close([Clamp]  optional  unsigned  short  code,  optional  DOMString  reason);    //  messaging    [TreatNonCallableAsNull]  attribute  Function?  onmessage;                      attribute  DOMString  binaryType;    void  send(DOMString  data);    void  send(ArrayBufferView  data);    void  send(Blob  data); };
CLIENT-SIDE WEBSOCKET API var  ws; if  (window.WebSocket)  {        output("WebSocket  supported  in  your  browser");        ws  =  new  WebSocket("ws://www.websockets.org");        //  Set  event  handlers.        ws.onopen  =  function  ()  {                output("onopen");        };        ws.onmessage  =  function  (e)  {                //  e.data  contains  received  string.                output("echo  from  server  :  "  +  e.data);        };        ws.onclose  =  function  ()  {                output("onclose");        };        ws.onerror  =  function  ()  {                output("onerror");        }; } else  {output("WebSocket  not  supported  in  your  browser");}
JAVA EE 7 SERVER-SIDE API package  org.javaee.glassfishwebsocket; import  org.glassfish.websocket.api.annotations.WebSocket; import  org.glassfish.websocket.api.annotations.WebSocketMessage; @WebSocket(path  =  "/echo") public  class  EchoBean  {        @WebSocketMessage        public  String  echo(String  message)  {                System.out.println("#####################  Message  received");                return  message  +  "  (from  your  server)";        } }
TOMCAT 7.0.29 SERVER-SIDE API SHOW THE CODE Not enough room for code in this slide ;-)
PROGRAMMING WEBSOCKETS Client-side frameworks ✦jquery.socket.js ✦https://github.com/flowersinthesand/jquery-socket/wiki ✦atmosphere.js ✦https://github.com/Atmosphere/atmosphere/wiki/jQuery.atmosphere.js-API ✦socket.io
WEBSOCKET SUPPORT JAVA-based Web servers with native support. The WebServer has API for WebSocket ✦Netty 3.3.x ✦Jetty 7.x, 8.x ✦Glassfish 3.1.2 ✦Tomcat 7.0.27
WHAT SHOULD WE DO? WE CAN DO IT!
WHAT IS ATMOSPHERE Atmosphere https://github.com/Atmosphere/atmosphere/ ✦portable framework for ✦long-polling ✦Streaming ✦Server-Send Events ✦WebSockets ✦can auto select best transport ✦abstracting from actual underlying container mechanism
THINKING ABOUT USE CASES ?
USE CASE OUR CLIENTS WebSockets really shine with following applications: ✦Live trading/sports ticker ✦Controlling medical equipment over the web ✦Chat applications ✦Multiplayer online games ✦Realtime updating social streams
BUNCH OF USEFUL LINKS ✦http://www.w3.org/TR/websockets/ MUST! ✦http://tools.ietf.org/html/rfc6455 MUST! ✦http://tomcat.apache.org/tomcat-7.0-doc/web-socket-howto.html ✦http://websocket-sdk.java.net/Introduction.html ✦https://github.com/Atmosphere/atmosphere/wiki/Supported- WebServers-and-Browsers ✦http://autobahn.ws/testsuite
Q AND A Q&A Put your questions
CONTACT US WWW.FARATASYSTEMS.COM INFO@FARATASYSTEMS.COM
FIND ME TWITTER GITHUB WWW.TWITTER.COM/GAMUSSA WWW.GITHUB.COM/GAMUSSA
THANK YOU THANK YOU FOR YOUR ATTENTION HTTP://WWW.FARATASYSTEMS.COM

WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers

  • 1.
    WEB SOCKETS CURRENT STATE FOR JAVA DEVELOPERS
  • 2.
    Web SOCKETS CURRENT STATE FOR JAVA DEVELOPERS PRESENTED BY VIKTOR GAMOV
  • 3.
    WEB SOCKETS AGENDA BIT OF MEET WEBSOCKETS Q&A HISTORY THE WEBSOCKETS IN ACTION SESSION ?
  • 4.
    OPTIONS FOR “REALTIME”WEB “LEGACY” WEB POLLING LONG-POLLING STEAMING Browser sends HTTP requests at Browser sends a request to the regular intervals and server and the server keeps the Browser sends a complete immediately receives a request open for a set period request, but the server sends response. However, real- time of time. If a notification is and maintains an open data is often not that received within that period, a response that is continuously predictable, making response containing the updated and kept open unnecessary requests message is sent to the client. If indefinitely (or for a set period inevitable and as a result, a notification is not received of time) many connections are opened within the set time period, the and closed needlessly in low- server sends a response to message-rate situations terminate the open request.
  • 5.
    WHAT IS WEBSOCKET “Reducingkilobytes of data to 2 bytes... and reducing latency from 150ms to 50 ms is far more than marginal. In fact, these two factors alone are enough to make WebSocket seriously interesting...” www.ietf.org/mail-archive/web/hybi/current/msg00784.html
  • 6.
    WHAT IS WEBSOCKETS? WEB SOCKET STANDARD PROTOCOL CLIENT-SIDE API SERVER-SIDE API Websocket is a HTML5 specification True real-time server standardized technology introduces WebSocket updates. Expected large (described in RFC6455) client side object. No penetration in Java to support low-overhead plugin required. world with upcoming bidirectional traffic from JavaEE 7 spec and your Web browser. JSR-356
  • 7.
    WEBSOCKET HANDSHAKE To Start full-duplex communication client should send UPGRADE request 1 2 3 4 SEND RECEIVE CHANGE LISTEN UPGRADE UPGRADE READYSTATE MESSAGE REQUEST RESPONSE TO OPEN EVENT
  • 8.
  • 10.
    WEBSOCKET INTERFACE [Constructor(DOMString  url,  optional  (DOMString  or  DOMString[])  protocols)] interface  WebSocket  :  EventTarget  {    readonly  attribute  DOMString  url;    //  ready  state    const  unsigned  short  CONNECTING  =  0;    const  unsigned  short  OPEN  =  1;    const  unsigned  short  CLOSING  =  2;    const  unsigned  short  CLOSED  =  3;    readonly  attribute  unsigned  short  readyState;    readonly  attribute  unsigned  long  bufferedAmount;    //  networking    [TreatNonCallableAsNull]  attribute  Function?  onopen;    [TreatNonCallableAsNull]  attribute  Function?  onerror;    [TreatNonCallableAsNull]  attribute  Function?  onclose;    readonly  attribute  DOMString  extensions;    readonly  attribute  DOMString  protocol;    void  close([Clamp]  optional  unsigned  short  code,  optional  DOMString  reason);    //  messaging    [TreatNonCallableAsNull]  attribute  Function?  onmessage;                      attribute  DOMString  binaryType;    void  send(DOMString  data);    void  send(ArrayBufferView  data);    void  send(Blob  data); };
  • 11.
    CLIENT-SIDE WEBSOCKET API var  ws; if  (window.WebSocket)  {        output("WebSocket  supported  in  your  browser");        ws  =  new  WebSocket("ws://www.websockets.org");        //  Set  event  handlers.        ws.onopen  =  function  ()  {                output("onopen");        };        ws.onmessage  =  function  (e)  {                //  e.data  contains  received  string.                output("echo  from  server  :  "  +  e.data);        };        ws.onclose  =  function  ()  {                output("onclose");        };        ws.onerror  =  function  ()  {                output("onerror");        }; } else  {output("WebSocket  not  supported  in  your  browser");}
  • 12.
    JAVA EE 7SERVER-SIDE API package  org.javaee.glassfishwebsocket; import  org.glassfish.websocket.api.annotations.WebSocket; import  org.glassfish.websocket.api.annotations.WebSocketMessage; @WebSocket(path  =  "/echo") public  class  EchoBean  {        @WebSocketMessage        public  String  echo(String  message)  {                System.out.println("#####################  Message  received");                return  message  +  "  (from  your  server)";        } }
  • 13.
    TOMCAT 7.0.29 SERVER-SIDEAPI SHOW THE CODE Not enough room for code in this slide ;-)
  • 14.
    PROGRAMMING WEBSOCKETS Client-side frameworks ✦jquery.socket.js ✦https://github.com/flowersinthesand/jquery-socket/wiki ✦atmosphere.js ✦https://github.com/Atmosphere/atmosphere/wiki/jQuery.atmosphere.js-API ✦socket.io
  • 15.
    WEBSOCKET SUPPORT JAVA-based Webservers with native support. The WebServer has API for WebSocket ✦Netty 3.3.x ✦Jetty 7.x, 8.x ✦Glassfish 3.1.2 ✦Tomcat 7.0.27
  • 16.
    WHAT SHOULD WEDO? WE CAN DO IT!
  • 17.
    WHAT IS ATMOSPHERE Atmosphere https://github.com/Atmosphere/atmosphere/ ✦portableframework for ✦long-polling ✦Streaming ✦Server-Send Events ✦WebSockets ✦can auto select best transport ✦abstracting from actual underlying container mechanism
  • 18.
  • 19.
    USE CASE OUR CLIENTS WebSockets really shine with following applications: ✦Live trading/sports ticker ✦Controlling medical equipment over the web ✦Chat applications ✦Multiplayer online games ✦Realtime updating social streams
  • 20.
    BUNCH OF USEFULLINKS ✦http://www.w3.org/TR/websockets/ MUST! ✦http://tools.ietf.org/html/rfc6455 MUST! ✦http://tomcat.apache.org/tomcat-7.0-doc/web-socket-howto.html ✦http://websocket-sdk.java.net/Introduction.html ✦https://github.com/Atmosphere/atmosphere/wiki/Supported- WebServers-and-Browsers ✦http://autobahn.ws/testsuite
  • 21.
    Q AND A Q&A Putyour questions
  • 22.
    CONTACT US WWW.FARATASYSTEMS.COM INFO@FARATASYSTEMS.COM
  • 23.
    FIND ME TWITTER GITHUB WWW.TWITTER.COM/GAMUSSA WWW.GITHUB.COM/GAMUSSA
  • 24.
    THANK YOU THANK YOU FOR YOUR ATTENTION HTTP://WWW.FARATASYSTEMS.COM