Your SlideShare is downloading. ×
  • Like
Web Sockets in Java EE 7
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Web Sockets in Java EE 7

  • 5,977 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,977
On SlideShare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
80
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. Java Day Web Sockets in Java EE 7 February 23, 2013Sivasubramaniam Arunachalam @sivaa_in http://www.meetup.com/BangaloreOpenJUG/events/102904102/
  • 2. It’s me!• Application Developer • Web/Enterprise/Middleware/B2B • Java/Java EE, Python/Django • 2002• Technical Consultant• Process Mentor• Speaker
  • 3. Agenda• Introduction to Web Sockets • History • Protocol Spec • Adoption• Java EE 7 Support• Demo
  • 4. Tweet Ping
  • 5. Web 1.0Web 2.0Web 3.0 Web 4.0
  • 6. 600+ M Active Users/Dayhttps://www.facebook.com/sitetour/chat.php
  • 7. 1991 http:// 1995Still 22 Years Old 2013 http?
  • 8. http/tcp (1991) (1974)request / response State less ~ 2k bytes ~ 150 ms
  • 9. ~ Real Time
  • 10. Pull Based (Polling) Periodic Polling (JS/AJAX) Latest Score? AUS 312/7 Latest Score? Same Latest Score? SameServer Client Latest Score? AUS 316/7 Latest Score? Same
  • 11. Push Based (Comet) Server Push/Long Polling (JS/AJAX/iframe) Latest Score? AUS 312/7 Latest Score?Server Client AUS 316/7 Latest Score?
  • 12. • Request / Response • Too Many • Server Connections• Heavy Headers• Outdated Content
  • 13. Streaming Server Side Hack Latest Score? AUS 312/7 (1/n)Server Client AUS 316/7 (2/n) IND 0/0 (n/n)
  • 14. Latest Score? (1/n) AUS 312/7 (n-1 to go)Server Server Buffer Client AUS 316/7 (2/n) AUS 312/7 (n-2 to go) AUS 316/7 IND 0/0 IND 0/0 (n/n) PROXY
  • 15. Others• RTMP • Adobe • Are you Still using Flash?• RTD • Windows/Excel • Non Web
  • 16. Web Sockets (to rescue)
  • 17. The Web Socket Way The Original Route Hey Server! Hi Client! Update me the Score AUS 312/7Server Client AUS 316/7 IND 0/0 Not Interested. Bye
  • 18. Hey Server! Hi Client! Update me the Score AUS 312/7 Update Over info too (93.0 ov)Server (94.0 ov) Client AUS 316/7 (95.0 ov) IND 0/0 (0.0 ov) Not Interested. Bye
  • 19. The Background
  • 20. Let’s Meet Next Year (2014) http://www.tavendo.de/webmq/resources/faq
  • 21. Server Side Client Side • Hand Shake • Java Script API • Data Transfer • Browser Behavior RFC 6455 http://www.tavendo.de/webmq/resources/faq
  • 22. Fundamentals• tcp + http• Full Duplex (Bi-Directional)• Native Browser Support• No Hacks• Not Limited to Web
  • 23. The Spec• 80 / 443 (plain/secure) • No Proxy/Firewall pains• Stream of Messages (Not Bytes)• ws:// & wss://• Only ONE Connection (up/down streams)
  • 24. Still Why?2 Bytes Header 1000 x (for each message)~ 50 ms (Latency) 3x
  • 25. 1 Message/Second per Client 1,000 clients 10,000 clients 1,00,000 clients http://www.codeproject.com/Articles/437342/DotNet-WebSocket-Programming
  • 26. The Upgrade• GET (request)• 101 (response code) • Not 200 OK• http:// -> ws://
  • 27. Client RequestGET /demo HTTP/1.1Origin : http://sivaa.inHost : sivaa.inConnection : UpgradeUpgrade : WebSocketWebSocket-Protocol : json, chat, <protocol>WebSocket-Version : 10WebSocket-extensions : compression, <extn>
  • 28. Server ResponseHTTP/1.1 101 Switching Protocols Connection : Upgrade Upgrade : WebSocket WebSocket-Protocol : json, chat, <protocol> WebSocket-Origin : http://sivaa.in WebSocket-Location : ws://sivaa.in/demo
  • 29. Challenge - ResponseChallenge by Client Sec-WebSocket-Key : Key (Random 128 bits -> Base 64)Response By Server Sec-WebSocket-Accept : Key + GUID* (SHA1) [NOT FOR SECURITY]* 258EAFA5-E914-47DA- 95CA-C5AB0DC85B11 (RFC 6455)
  • 30. Client / ServerPeer <-> Peer
  • 31. Data Transfer• Frames (TCP)•• No request / response behavior • No Correlation too • Independent • # of requests != # of responses
  • 32. And No • Headers • Cookies • Authentication
  • 33. Sub Protocols• Custom Message Patterns• Technical / Business• Request / Response • 1–1 • 1 to Many • Acknowledgements
  • 34. Ping / Pong• Keep-Alive Client -> Ping• Heart Beat Server -> Pong• Latency Metrics• N/W Status Probing• Detect Failed Connections
  • 35. Browser Support http://caniuse.com/#feat=websockets
  • 36. IDL (Java Script)Server Support http://www.w3.org/TR/websockets/
  • 37. http://www.w3.org/TR/websockets/
  • 38. http://www.w3.org/TR/websockets/
  • 39. http://www.w3.org/TR/websockets/
  • 40. http://www.w3.org/TR/websockets/
  • 41. Developer Friendly1. var ws = new WebSocket("ws://sivaa.in/demo"); CONNECTING2. ws.onopen = function() { ws.send("Hello Server!"); OPEN };3. ws.onmessage = function(event) { alert("Reply from Server " + event.data); };n-1. ws.send("This is the message sent by the client");n. ws.close() CLOSING CLOSED
  • 42. The Guards (Proxy / Firewall)• Closing Long Lived Connections • Unresponsive Server• Buffering Server Response • Non Encryption • More Latency
  • 43. Web Sockets and The Guards• Web Sockets doesn’t Proxy• Stripping HTTP Headers • Upgrade • Options to disable• Rejecting Server Response • Frames (HTTP Headers Expected)• wss:// - No issues
  • 44. The Hidden Blades• 301• Limited Support• Inconsistent Behavior
  • 45. Java EE 7 & Web Socket• JSR 356• Java EE 7• Tyrus ( http://tyrus.java.net/ ) • Web Socket SDK • Reference Implementation
  • 46. Server Side Capabilities (Expected) • Handshake Response to Clients • Source/Origin Check • URI Resolving & Matching • Sub Protocols Negotiation • Extension Negotiation
  • 47. Handlers• End point (to handle life cycle events)• Session (Current Active Session)• Remote End Point (Peer)• Message Handler (incoming messages)• Error Handler
  • 48. Packages• javax.websocket.*• javax.net.websocket.*http://java.net/projects/websocket-spec/sources/source-code-repository/show/tags/javax.net.websocket-api-1.0-b08/src/main/java?rev=213
  • 49. Web Server Support• Apache Tomcat 7• GlassFish 3.1• Jetty 7• JBoss 7• And much more
  • 50. GlassFish• Annotations• Reference Implementation• Web Sockets SDK / mvn• Samples to Begin with
  • 51. Demo• GlassFish Promoted Build• # svn checkout https://svn.java.net/svn/websocket-sdk~source-code-repository• # mvn clean install (in websocket-sdk~source-code-repositorytrunksamples)• Import in Latest Net Beans• Run it
  • 52. Thank You! siva@sivaa.inbit.ly/sivaa_in bit.ly/sivasubramaniam
  • 53. References• http://www.inc.com/ss/brief-history-time-management#7• http://resources3.news.com.au/images/2013/01/30/1226564/845955-tim-berners-lee.jpg• http://netdna.webdesignerdepot.com/uploads/2009/01/macii.jpg#old%20apple%20computer%20559x450• http://3.bp.blogspot.com/_zVkfb2MIt4A/S8f_qzhuhRI/AAAAAAAAAjg/2idf7_G4wxo/s1600/apple-imac.png• http://www.softwareforeducation.com/wikileki/images/c/c4/Simplex-half-full.gif• http://www.mediafly.com/wp-content/uploads/Speed_Rocket-2.png• http://weaponsman.com/wp-content/uploads/2013/01/thumbs-down.png• http://m.flikie.com/ImageData/WallPapers/d1bef9f8be6d479387953929c766699a.jpg• http://www.tavendo.de/webmq/resources/faq• http://deadliestwebattacks.com/tag/websocket/• http://en.wikipedia.org/wiki/WebSocket• http://www.infoq.com/articles/Web-Sockets-Proxy-Servers