A SockJS server implementation for Play Framework.

play2-sockjs api aims to be as similar as possible to the WebSocket one provided by Play Framework:

// Play WebSocket api:
def websocket = WebSocket.using[String](handler)

// play2-sockjs api:
def sockjs = SockJS.using[String](handler)

// same request handler
val handler = { (request: RequestHeader) =>
  // Log events to the console
  val in = Iteratee.foreach[String](println).map { _ =>
  // Send a single 'Hello!' message and close
  val out = Enumerator("Hello!") >>> Enumerator.eof
  (in, out)

It provides api for Scala and Java. All transports offered by SockJS have been implemented according to the 0.3.3 protocol specifications. Currently passes all transport tests from the specs except for test_haproxy, it should impact only users that uses WebSocket Hixie-76 protocol behind HAProxy.

Current versions:
    Play 2.1.x : 0.1.6
    Play 2.2.x : 0.2.6
    Play 2.3.x : 0.3.1
    Play 2.4.x : 0.4.0
    Play 2.5.x : 0.5.3
    Play 2.6.x : 0.6.0
    Play 2.7.x : 0.7.1
    Play 2.8.x : 0.8.2
    Play 2.9.x : 0.9.0
    Play 3.0.x : 0.10.0

What is SockJS?

SockJS is a browser JavaScript library that provides a WebSocket-like object. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication channel between the browser and the web server.

Under the hood SockJS tries to use native WebSockets first. If that fails it can use a variety of browser-specific transport protocols and presents them through WebSocket-like abstractions.

SockJS is intended to work for all modern browsers and in environments which don't support WebSocket protocol, for example behind restrictive corporate proxies.


For installation see Installing

For usage see API reference

Want to learn more? See the wiki