Knoldus Software LLP

Using WebSockets In Play!

Neelkanth Sachdeva
Software Consultant

neelkanthsachdeva.wordpress.com
Agenda
Short Polling
Long Polling
WebSockets
Websockets with Play !
The Play Chat Application Using Wesockets
Short Polling

Drawbacks :
Resource Intensive
Slow Even Very Slow
One Request / One Response
Long Polling

Drawbacks :
- Half Duplax
- Again one request / one response
Whats our probelm

Lots of incoming messages
Websockets
WebSocket Features & Limitations
Features :
Full duplax communication
Real time messages
Efficient & Fast
Drawbacks :
Available with newer browsers
Using Websockets with Play !

Producer

Consumer
Using Websockets with Play !

Producer
Enumerator

Consumer
Iteratee
Iteratees
The Consumer
Consumes chunks from Producer
Enumerator
The Producer
- Produces typed chunks
- Only produces if consumer is there.
At Server :
Creating a websocket connection needs a
Producer (Enumerator) & a Consumer
(Iteratee)
At Client :
Creating a socket connection.
var socket = new WebSocket(“ws://localhost:9000”)

The Events
- onmessage
- onopen
- onclose
Understand it through play sample chat
application available here :
https://github.com/playframework/playframework/tree/master/samples/scala/websocket-chat
Cheers !

Using Websockets in Play !