websockets: the current state of the most valuable html5 api for java developers
DESCRIPTION
TRANSCRIPT
![Page 1: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/1.jpg)
WEB SOCKETSCURRENT STATE
FOR JAVA DEVELOPERS
![Page 2: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/2.jpg)
CURRENT STATE FOR JAVA DEVELOPERS
Web SOCKETS
VIKTORGAMOV
PRESENTEDBY
![Page 3: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/3.jpg)
WEB SOCKETS
BIT OFHISTORY
MEETTHE WEBSOCKETS
WEBSOCKETSIN ACTION
Q & ASESSION
AGENDA
?
![Page 4: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/4.jpg)
“LEGACY” WEBPOLLING LONG-POLLING STEAMING
OPTIONS FOR “REALTIME” WEB
Browser sends a request to the server and the server keeps the request open for a set period of time. If a notification is received within that period, a response containing the message is sent to the client. If a notification is not received within the set time period, the server sends a response to terminate the open request.
Browser sends a complete request, but the server sends and maintains an open response that is continuously updated and kept open indefinitely (or for a set period of time)
Browser sends HTTP requests at regular intervals and immediately receives a response. However, real- time data is often not that predictable, making unnecessary requests inevitable and as a result, many connections are opened and closed needlessly in low-message-rate situations
![Page 5: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/5.jpg)
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
![Page 6: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/6.jpg)
WEB SOCKETSTANDARD PROTOCOL CLIENT-SIDE API SERVER-SIDE API
WHAT IS WEBSOCKETS?
HTML5 specification introduces WebSocket client side object. No plugin required.
True real-time server updates. Expected large penetration in Java world with upcoming JavaEE 7 spec and JSR-356
Websocket is a standardized technology (described in RFC6455) to support low-overhead bidirectional traffic from your Web browser.
![Page 7: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/7.jpg)
1 2 3 4
SEND
UPGRADEREQUEST
RECEIVE
UPGRADERESPONSE
CHANGE
READYSTATETO OPEN
LISTEN
MESSAGEEVENT
WEBSOCKET HANDSHAKE
To Start full-duplex communication client should send UPGRADE request
![Page 8: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/8.jpg)
DEMO
HANDSHAKE DEMO
![Page 9: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/9.jpg)
![Page 10: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/10.jpg)
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);};
![Page 11: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/11.jpg)
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");}
![Page 12: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/12.jpg)
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)"; }}
![Page 13: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/13.jpg)
TOMCAT 7.0.29 SERVER-SIDE API
SHOW THE
CODENot enough room for code in this slide ;-)
![Page 14: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/14.jpg)
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
![Page 15: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/15.jpg)
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
![Page 16: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/16.jpg)
WHAT SHOULD WE DO?
WE CAN DO IT!
![Page 17: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/17.jpg)
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
![Page 18: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/18.jpg)
?
THINKING ABOUT USE CASES
![Page 19: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/19.jpg)
OUR CLIENTSUSE CASE
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
![Page 20: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/20.jpg)
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
![Page 21: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/21.jpg)
Q AND A
Q&APut your questions
![Page 22: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/22.jpg)
WWW.FARATASYSTEMS.COM
CONTACT US
![Page 23: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/23.jpg)
TWITTERWWW.TWITTER.COM/GAMUSSA
GITHUBWWW.GITHUB.COM/GAMUSSA
FIND ME
![Page 24: WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers](https://reader035.vdocuments.mx/reader035/viewer/2022070312/5538904b550346bb318b47ee/html5/thumbnails/24.jpg)
THANK YOUFOR YOUR ATTENTION
HTTP://WWW.FARATASYSTEMS.COM
THANK YOU