websockets and java

12
WebSocket Bozhidar Bozhanov ...one day at home I decided I'm bored => a WebSocket-based game for http://computoser.com

Upload: bozhidar-bozhanov

Post on 08-May-2015

1.496 views

Category:

Technology


1 download

DESCRIPTION

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

TRANSCRIPT

Page 1: WebSockets and Java

WebSocket

Bozhidar Bozhanov

...one day at home I decided I'm bored => a WebSocket-based game for http://computoser.com

Page 2: WebSockets and Java

Usecases

● Games● Stock-exchange application● ...anything, really

Page 3: WebSockets and Java

Why WebSocket?

● Push● Real-time communication● Resource-light● Intuitive, non-hacky

Page 4: WebSockets and Java

Up to now

● Ajax polling (a.k.a. "are we there yet?")● Long-polling, streaming● Plugins – flash/applets/ActiveX● Problems: hacky, resource-heavy, server-

thread-unfriendly

Page 5: WebSockets and Java

WebSocket

● Standard (HTML5) ● TCP, full-duplex● More effective on the server-side● High-level protocols ontop – STOMP, WAMP,

etc.

Page 6: WebSockets and Java

Client-side

● Standard JavaScript API● Browser support – problematic● SockJS, socket.io, fallbacks

Page 7: WebSockets and Java

Server-side

● node.js● Java – Java EE WebSocket API (JSR-356)● Servlet container implementations – thread

pools● Spring-MVC API, Spring Messaging API

Page 8: WebSockets and Java

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)

Page 9: WebSockets and Java

Messaging

● Alternative architecture● Using a message broker

(simple/ActiveMQ/RabbitMQ/..) behind spring● STOMP over WebSocket● Client subscribes for events

Page 10: WebSockets and Java

DDD and TDD

● DDD comes naturally● Objects and their workflows are easily testable● Very few mocks, comparable to spring-mvc

@RequestMappings

Page 11: WebSockets and Java

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.

Page 12: WebSockets and Java

Conclusion

● It's cool :)