Your SlideShare is downloading. ×
0
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Writing Portable WebSockets in Java
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Writing Portable WebSockets in Java

2,368

Published on

Write WebSockets Applications using the Atmosphere Framework, deploy them anywhere, with any browsers.

Write WebSockets Applications using the Atmosphere Framework, deploy them anywhere, with any browsers.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,368
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
33
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Writing Portable WebSocket in Java Jeanfrancois Arcand twitter.com/jfarcand
  • 2. Pardon?• Worked 10 years for Sun Microsystems • Active Commiter on Tomcat 4/5 • Active Commiter GlassFish 1/2/3 • Glassfish v3 extensible container kernel • Performance/Scalability • Creator of the Grizzly NIO Framework• Creator of the AHC (AsyncHttpClient) library• Creator of Atmosphere
  • 3. Atmosphere Apache 2 Github ~470 « followers » Client + Supported server ~25frameworks Scala, Groovy, JRuby, Java Since 2008 20 000 downloads per months1.0.0.beta3
  • 4. Atmosphere Apache 2 Github ~450 « followers » Client + Supported EXTREMEL server ~25 Y ACTIVEframeworks !!! Scala, Groovy, JRuby, Java Since2008 20 000 downloads per months1.0.0.beta2
  • 5. Today’s Presentation WebSocket
  • 6. Today’s Presentation WebSocketDefinition
  • 7. Today’s Presentation WebSocketDefinition Free for all!!!
  • 8. Today’s Presentation WebSocketC’est quoiDefinition Free for Free for all!!! all! Atmospher e
  • 9. Today’s Presentation WebSocket Definition Free for all! Atmospher eConcepts
  • 10. Today’s Presentation WebSocket C’est quoi Definition Free for all!!! all! Atmospher eConcepts Demo
  • 11. WebSocketsis a web technology providing for bi-directional, full-duplex communications channels over a single TCP connection. The WebSocket API is being standardized by the W3C, and the WebSocket protocol has been standardized by the IETF as RFC 6455
  • 12. Before (Long-Polling) RequestBrowse Server r
  • 13. Before (Long-Polling) RequestBrowse Server r
  • 14. Before (Long-Polling) RequestBrowse Server r Response
  • 15. Oups!! RequestBrowse None Server r
  • 16. Oups! RequestBrowse Server r Zzzz
  • 17. Better! RequestBrowse Server r Cache
  • 18. Better! RequestBrowse Server r Cache
  • 19. Pushing the Protocol (HTTP Streaming) RequestBrowse Server r
  • 20. Pushing the Protocol (HTTP Streaming) RequestBrowse Server r
  • 21. Pushing the Protocol (HTTP Streaming) RequestBrowse Server r Response
  • 22. Pushing the Protocol (HTTP Streaming) RequestBrowse Server r Response Response
  • 23. Oups!! RequestBrowse Server r Hell!!! Response Response
  • 24. Pushing the Protocol (HTTP Streaming) RequestBrowse Server r Hell!!! Hack Response Response
  • 25. Oups!!! RequestBrowse Server r Response Proxy Response
  • 26. Better RequestBrowse Server r Response Cache Response
  • 27. Better RequestBrowse Server r Response Cache « HeartBeat Response »
  • 28. Better: Server Side Events (SSE) RequestBrowse Server r Response Response
  • 29. Oups!!! RequestBrowse Server r Response Proxy Response
  • 30. Better RequestBrowse Server r Response Cache « HeartBeat Response »
  • 31. WebSockets HanshakeBrowse Server r
  • 32. WebSockets HanshakeBrowse Server r OK
  • 33. WebSockets RequestBrowse Server r
  • 34. WebSockets RequestBrowse Server r
  • 35. WebSocketsBrowse Server r Response
  • 36. WebSockets RequestBrowse Server r
  • 37. WebSockets Request RequestBrowse Server r
  • 38. WebSockets Request RequestBrowse Server r
  • 39. WebSocketsBrowse Server r Response Response
  • 40. AnytimeBrowse Server r Response
  • 41. Life is good, lalalalalalaBrowse Server r Response
  • 42. Oups!!Browse Server r Response Proxy
  • 43. Better!Browse Server r Response Cache
  • 44. First RequestT 127.0.0.1:65062 -> 127.0.0.1:8080 [AP]GET / HTTP/1.1.Upgrade: websocket.Connection: Upgrade.Host: 127.0.0.1:8080.Origin: http://127.0.0.1:8080.Sec-WebSocket-Key: Tz9qdt3lmte6Slf+GvpRqQ==.Sec-WebSocket-Version: 13.Sec-WebSocket-Extensions: x-webkit-deflate-frame.
  • 45. ResponseT 127.0.0.1:8080 -> 127.0.0.1:51292 [AP]HTTP/1.1 101 Switching Protocols.Upgrade: WebSocket.Connection: Upgrade.Sec-WebSocket-Accept:HVXA7SqH5uYeN6aD9tZ0JQbfTJA=.
  • 46. Life is good, lalalalalalaT 127.0.0.1:8080 -> 127.0.0.1:51292 [AP]HTTP/1.1 101 Switching Protocols.Upgrade: WebSocket.Connection: Upgrade.Sec-WebSocket-Accept:HVXA7SqH5uYeN6aD9tZ0JQbfTJA=.
  • 47. OUPS!!!T 127.0.0.1:8080 -> 127.0.0.1:65064 [AP]HTTP/1.1 501 Not Implemented.Server: Apache-Coyote/1.1.X-Atmosphere-error: Websocket protocol notsupported.Transfer-Encoding: chunked.Date: Fri, 15 Jun 2012 10:06:30 GMT.Connection: close..
  • 48. WebSocket API – Standard JavaScriptwebsocket = new WebSocket(wsUri);websocket.onopen = function(evt) { …};websocket.onclose = function(evt) { …};websocket.onmessage = function(evt) { …};websocket.onerror = function(evt) { …};webSocket.send(…)
  • 49. WebSocket API – JavaJetty 7, GlassFish 3.1, Netty 3, Tomcat7.0.27, Resin 4, JBoss PluginJSR 356:http://jcp.org/en/jsr/detail?id=356AHC (Client -> De facto)http://github.com/sonatype/async-http-client
  • 50. Life is good, lalalalalala
  • 51. OUPS!!!
  • 52. Ready?Safari Tomcat 7Firefox Jetty7 Jetty8Chrome GlassFisOpera h3. GlassFis IE h 312
  • 53. Free for allSafari Tomcat 7Firefox Jetty7 Jetty8Chrome GlassFisOpera h3. GlassFis IE h 312
  • 54. Free for allSafari Tomcat 7Firefox Jetty7 Imdat!! Jetty8Chrome GlassFisOpera h3. GlassFis IE h 312
  • 55. Free for allSafari Tomcat 7 Streamin Jetty7Firefox g Imdat!! Jetty8Chrome GlassFisOpera h3. GlassFis IE h 312
  • 56. Free for allSafari Tomcat 7 Streamin Jetty7Firefox g Imdat!!SSE Jetty8Chrome GlassFisOpera h3. GlassFis IE h 312
  • 57. Free for allSafari Tomcat 7 Streamin Jetty7Firefox g Imdat!!SSE Jetty8Chrome GlassFisOpera JSONP h3. GlassFis IE h 312
  • 58. Free for allSafari Tomcat 7 Streamin Jetty7Firefox g Imdat!!SSE Jetty8Chrome GlassFisOpera Long JSONP h3. GlassFis IE Polling h 312
  • 59. Safari Tomcat 7Firefox Jetty7 AtmosphereChrome to the Jetty8 rescue!!! GlassFisOpera h3. GlassFis IE h 312
  • 60. Atmosphere -WebSocketsSafari Tomcat 7 Jetty7 Atmosphere APIFirefox atmosphere.js Jetty8Chrome GlassFisOpera h3. GlassFis IE h 312
  • 61. Atmosphere - HTML5 Server Side EventsSafari Tomcat 7 Jetty7 Atmosphere APIFirefox atmosphere.js ServletChrome 3 WebLogiOpera c GlassFis IE h 312
  • 62. Atmosphere Long-Polling/HTTP StreamingSafari JBoss Jetty7 Atmosphere APIFirefox atmosphere.js ServletChrome 3 WebLogiOpera c. GlassFis IE h
  • 63. AtmosphereSafari JBoss Jetty7 Atmosphere APIFirefox atmosphere.js SameChrome API, transport Servlet 3 independent!! WebLogiOpera c. GlassFis IE h
  • 64. Socket.IO, GWT, Wicket, JSF, etc.Safari JBoss Jetty7 Atmosphere APIFirefox Socket.IO ServletChrome 3 WebLogiOpera c. GlassFis IE h
  • 65. PORTABLE!!!!!Safari JBoss Jetty7 Atmosphere APIFirefox Socket.IO PORTABLE ServletChrome 3 WebLogiOpera c. GlassFis IE h
  • 66. Big Big Big Mistake• Frameworkthat support ONLY WebSockets Going into Production? IMPOSSIBLE
  • 67. Atmosphere
  • 68. Definition• Suspend: open a channel• Resume: close a channel• Broadcast: push message to one or more channel
  • 69. ComponentsAtmosphere.js Interceptor(s) Handler(s)
  • 70. ComponentsAtmosphere.js Javascript Interceptor(s) client Handler(s)
  • 71. ComponentsAtmosphere.js Interceptor(s) Intercepts/ Filters Handler(s)
  • 72. ComponentsAtmosphere.js Application Interceptor(s) s Logic Handler(s)
  • 73. ComponentsAtmosphere.js Your Servlet Interceptor(s) ServletHandler
  • 74. Components Your ServletAtmosphere.js Based Framework Interceptor(s) ServletHandler
  • 75. ComponentsAtmosphere.js ws Your Servlet Interceptor(s) ServletHandler
  • 76. ComponentsAtmosphere.js ws Your Servlet ss e Interceptor(s) ServletHandler
  • 77. ComponentsAtmosphere.js ws Your Servlet ss http e Interceptor(s) ServletHandler
  • 78. RequestBrowse rBrowse Server rBrowse r
  • 79. RequestBrowse rBrowse Server rBrowse r
  • 80. SuspendBrowse rBrowse Server rBrowse r
  • 81. SuspendBrowse r SBrowse Server rBrowse r
  • 82. SuspendBrowse r SBrowse Server rBrowse r
  • 83. SuspendBrowse r SBrowse Server rBrowse r
  • 84. BroadcastBrowse r B SBrowse Server rBrowse r
  • 85. BroadcastBrowse r B SBrowse Server rBrowse r
  • 86. ResumeBrowse r BBrowse Server r RBrowse r
  • 87. ResumeBrowse r BBrowse Server S rBrowse r
  • 88. Broadcaster• Default: in-memory• Cloud • RedisBroadcaster • JMSBroadcaster • XMPPBroadcaster • HazelcastBroadcaster • JGroupsBroascaster• Multi-Threads, Async I/O par default
  • 89. Broadcaster CloudBrowse r S ServerBrowse rBrowse S Server r
  • 90. Broadcaster CloudBrowse r S ServerBrowse rBrowse S Server r
  • 91. Broadcaster CloudBrowse B r S ServerBrowse rBrowse S Server r
  • 92. Broadcaster CloudBrowse B r ServerBrowse rBrowse r Server
  • 93. Broadcaster CloudBrowse r ServerBrowse r BBrowse r Server
  • 94. Broadcaster CloudBrowse r ServerBrowse rBrowse r Server
  • 95. Atmosphere API• WebSocketHandler • Only WebSocket (WARNING)!• AtmosphereHandler • All transport• Jersey Resource • All transport• Meteor • All transport
  • 96. WebSocket Sub Protocol• WebSocketProtocol Define your own websocket protocol• SimpleHttpProtocol WebSocket’s message mapped to HTTP POST, avec read/write asynchrone.• SwaggerSocket:REST over WebSockets -> Powerful Protocol
  • 97. Let’s have some fun
  • 98. Single Client to Rule Them Allhttps://github.com/Atmosphere/atmosphere/blob/master/samples/chat/src/m ain/webapp/jquery/application.js#L1
  • 99. WebSockethttps://github.com/Atmosphere/atmosphere/blob/master/samples/websocke t-chat/src/main/java/org/atmosphere/samples/chat/WebSocketChat.java#L33
  • 100. WebSocket, SSE, long-pollinghttps://github.com/Atmosphere/atmosphere/blob/master/samples/chat/src/main/java/org/atmosphere/samples/chat /ChatAtmosphereHandler.java#L33
  • 101. Socket IOhttps://github.com/Atmosphere/atmosphere/blob/master/samples/socketio-chat/src/main/java/org/atmosphere/samples/chat/SocketIOChatAtmosphere Handler.java#L34
  • 102. Jerseyhttps://github.com/Atmosphere/atmosphere/blob/master/samples/sse-rest-chat/src/main/java/org/atmosphere/samples/chat/jersey/ResourceChat.java #L32
  • 103. JAXRS 2https://github.com/Atmosphere/atmos phere/blob/master/samples/jaxrs2-chat/src/main/java/org/atmosphere/samples/chat/jaxrs2/Jaxrs2Chat.java#L3 4
  • 104. SwaggerSocket• REST over WebSocket• JSON Based• Simple• Works with HTTP• Multi-Request/Response
  • 105. Conclusion Join the RevolutionIt’s open source, it’s free tojumps in!!
  • 106. twitter.com/jfarcand twitter.com/atmo_framework twitter.com/swaggersockethttp://github.com/Atmosphere/atmospherehttp://github.com/wordnik/swaggersocket

×