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

21,773 views

Published on

Published in: Technology
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total views
21,773
On SlideShare
0
From Embeds
0
Number of Embeds
16,520
Actions
Shares
0
Downloads
37
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

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 AGENDABIT OF MEET WEBSOCKETS Q&AHISTORY THE WEBSOCKETS IN ACTION SESSION ?
  4. OPTIONS FOR “REALTIME” WEB “LEGACY” WEB POLLING LONG-POLLING STEAMINGBrowser sends HTTP requests at Browser sends a request to theregular intervals and server and the server keeps the Browser sends a completeimmediately receives a request open for a set period request, but the server sendsresponse. However, real- time of time. If a notification is and maintains an opendata is often not that received within that period, a response that is continuouslypredictable, making response containing the updated and kept openunnecessary requests message is sent to the client. If indefinitely (or for a set periodinevitable and as a result, a notification is not received of time)many connections are opened within the set time period, theand closed needlessly in low- server sends a response tomessage-rate situations terminate the open request.
  5. WHAT IS WEBSOCKET“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 makeWebSocket seriously interesting...” www.ietf.org/mail-archive/web/hybi/current/msg00784.html
  6. WHAT IS WEBSOCKETS? WEB SOCKETSTANDARD 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 LISTENUPGRADE UPGRADE READYSTATE MESSAGE REQUEST RESPONSE TO OPEN EVENT
  8. DEMOHANDSHAKE DEMO
  9. 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);};
  10. CLIENT-SIDE WEBSOCKET APIvar  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");}
  11. JAVA EE 7 SERVER-SIDE APIpackage  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)";        }}
  12. TOMCAT 7.0.29 SERVER-SIDE APISHOW THE CODENot enough room for code in this slide ;-)
  13. PROGRAMMING WEBSOCKETSClient-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
  14. WEBSOCKET SUPPORTJAVA-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
  15. WHAT SHOULD WE DO? WE CAN DO IT!
  16. WHAT IS ATMOSPHEREAtmospherehttps://github.com/Atmosphere/atmosphere/✦portable framework for ✦long-polling ✦Streaming ✦Server-Send Events ✦WebSockets✦can auto select best transport✦abstracting from actual underlying containermechanism
  17. THINKING ABOUT USE CASES ?
  18. USE CASE OUR CLIENTSWebSockets really shine with following applications:✦Live trading/sports ticker✦Controlling medical equipment over the web✦Chat applications✦Multiplayer online games✦Realtime updating social streams
  19. 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
  20. Q AND AQ&APut your questions
  21. CONTACT US WWW.FARATASYSTEMS.COM INFO@FARATASYSTEMS.COM
  22. FIND ME TWITTER GITHUBWWW.TWITTER.COM/GAMUSSA WWW.GITHUB.COM/GAMUSSA
  23. THANK YOUTHANK YOU FOR YOUR ATTENTION HTTP://WWW.FARATASYSTEMS.COM

×