WebSockets: um upgrade de comunicação no HTML5

1,333 views
1,279 views

Published on

Conheça a nova tecnologia WebSockets, e como utilizá-la em Java

Published in: Technology, News & Politics
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,333
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
39
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

WebSockets: um upgrade de comunicação no HTML5

  1. 1. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 132WebSockets: um upgradede comunicação no HTML5Bruno BorgesOracle Product ManagerJava Evangelist@brunoborges
  2. 2. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 133Bruno BorgesOracle Product Manager / EvangelistDesenvolvedor, GamerEntusiasta em Java Embedded eJavaFXTwitter: @brunoborges
  3. 3. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 134Java EE 7está pronto!
  4. 4. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 135Java EE 7 Escopo●Produtividade de Desenvolvimento– Menos código Boilerplate– Funcionalidades mais ricas– Mais convenções e defaults●Suporte a HTML5– WebSocket– JSON– HTML5 FormsJSR 342
  5. 5. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 136Java EE 7EJB 3.2Servlet 3.1CDIExtensionsBatch 1.0WebFragmentsJCA 1.7JMS 2.0JPA 2.1Managed Beans 1.0Concurrency 1.0CommonAnnotations 1.1Interceptors1.2, JTA 1.2CDI 1.1JSF 2.2,JSP 2.3,EL 3.0JAX-RS 2.0,JAX-WS 2.2JSON 1.0WebSocket 1.0
  6. 6. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 137Construindo aplicações HTML5com WebSockets Java API WebSocket 1.0 – JSR 356 RFC 6455 W3C Web Sockets API– JavaScript objects
  7. 7. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 138HTTP vs WebSockets Protocolo HTTP é half-duplex Gambiarras– Polling– Long polling– Streaming WebSocket resolve o problemade uma vez por todas– Full-duplex
  8. 8. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 139WebSockets Handshake Cliente solicita um UPGRADE Server confirma (Servlet 3.1) Cliente recebe o OK Inicia a sessão WebSockethttp://farata.github.io/slidedecks/state_of_websocket/slides.html#13.4
  9. 9. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1310WebSockets API for Javascriptvar ws;if (window.WebSocket) {ws = new WebSocket("ws://echo.websocket.org");ws.onopen = function () {console.log("onopen");};ws.onmessage = function (e) {// e.data contains received string.console.log("echo from server : " + e.data);};ws.onclose = function () { console.log("onclose"); };ws.onerror = function () { console.log("onerror"); };} else {console.log("WebSocket not supported in your browser");}if (ws.readyState === 1) ws.send("Hello WebSocket!");
  10. 10. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1311WebSockets Facts WS não funciona por proxies Suporte incompleto em browsers Desafios de configurar WebSocket com LBRs
  11. 11. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1312WebSockets e Browsers
  12. 12. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1313WebSockets só roda em navegadores Web?
  13. 13. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1314Clientes além de Navegadores iOS– SocketRocket Android– Async HTTP Client– AutobahnAndroid Java libs and JavaFX– WebView HTML5 component
  14. 14. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1315Ping Pong Serve para manter a conexão ativa Programaticamente possível interceptar– Server– Client
  15. 15. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1316Java API for WebSockets 1.0 API para definir WebSockets, tanto Client como Server– Annotation-driven (@ServerEndpoint)– Interface-driven (Endpoint)– Client (@ClientEndpoint) SPI para data frames– Negociação handshake na abertura do WebSocket Integração com o Java EE Web container
  16. 16. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1317Java API for WebSockets 1.0import javax.websocket.*;import javax.websocket.server.*;@ServerEndpoint(“/hello”)public class HelloBean {    @OnMessage    public String sayHello(String name) {        return “Hello “ + name;    }}
  17. 17. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1318Java API for WebSockets 1.0@ServerEndpoint(“/chat”)public class ChatBean {    @OnOpen    public void onOpen(Session peer) {        peers.add(peer);    }    @OnClose    public void onClose(Session peer) {        peers.remove(peer);    }    @OnMessage    public void message(String msg, Session client) {        peers.forEach(p ­> p.getRemote().sendMessage(msg));    }}
  18. 18. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1319DEMOWebSockets
  19. 19. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1320Casos de Uso para WebSockets Placar de jogos Controlar equipamentos pela Web Chat MMORPG Atualização de Social Streams em tempo real Ferramentas em geral com auto refresh
  20. 20. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1321Perguntas?
  21. 21. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1322Créditos: Fara Systems Conteúdo de WebSockets extraído de:farata.github.io/slidedecks/state_of_websocket/slides.html#1.0
  22. 22. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1323OBRIGADO!@brunoborgesblogs.oracle.com/brunoborges
  23. 23. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1324The preceding is intended to outline our general product direction. It is intendedfor information purposes only, and may not be incorporated into any contract.It is not a commitment to deliver any material, code, or functionality, and shouldnot be relied upon in making purchasing decisions. The development, release,and timing of any features or functionality described for Oracle’s productsremains at the sole discretion of Oracle.
  24. 24. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1325

×