WebSockets and Java

2,606 views

Published on

A short presentation on WebSockets and their Java server-side usage.

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

No Downloads
Views
Total views
2,606
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
17
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

WebSockets and Java

  1. 1. WebSocket Bozhidar Bozhanov ...one day at home I decided I'm bored => a WebSocket-based game for http://computoser.com
  2. 2. Usecases ● Games ● Stock-exchange application ● ...anything, really
  3. 3. Why WebSocket? ● Push ● Real-time communication ● Resource-light ● Intuitive, non-hacky
  4. 4. Up to now ● Ajax polling (a.k.a. "are we there yet?") ● Long-polling, streaming ● Plugins – flash/applets/ActiveX ● Problems: hacky, resource-heavy, serverthread-unfriendly
  5. 5. WebSocket ● Standard (HTML5) ● TCP, full-duplex ● More effective on the server-side ● High-level protocols ontop – STOMP, WAMP, etc.
  6. 6. Client-side ● Standard JavaScript API ● Browser support – problematic ● SockJS, socket.io, fallbacks
  7. 7. Server-side ● node.js ● Java – Java EE WebSocket API (JSR-356) ● ● Servlet container implementations – thread pools Spring-MVC API, Spring Messaging API
  8. 8. Java WebSocket API vs Spring ● ● Very similar One handler per endpoint, differentiate based on payload ● Out-of-the-box dependency injection with spring ● No annotation configuration in spring (yet)
  9. 9. Messaging ● ● Alternative architecture Using a message broker (simple/ActiveMQ/RabbitMQ/..) behind spring ● STOMP over WebSocket ● Client subscribes for events
  10. 10. DDD and TDD ● DDD comes naturally ● Objects and their workflows are easily testable ● Very few mocks, comparable to spring-mvc @RequestMappings
  11. 11. Security and authentication ● WSS vs WS (ws://example.com/game) ● No same-origin policy. Origin header. ● Validate input and output ● Authentication – cookies? Cookie-like workflow.
  12. 12. Conclusion ● It's cool :)

×