WebSockets in Play

WebSockets cannot be defined using Action since they should be bidirectional. Play provides a helper to assist with WebSockets, which is documented at https://www.playframework.com/documentation/2.3.x/api/scala/index.html#play.api.mvc.WebSocket$.

Note

WebSockets, which are defined using the helper, use the Play server's underlying TCP port.

WebSockets can be defined similarly to Actions in Play applications. Starting from Play 2.3, a WebSocket helper finds a method to define WebSocket interactions using an Actor. However, before we learn more about the methods provided by the helper, let's take a small detour and get a little familiar with the Actor Model and Akka Actors.

Get Mastering Play Framework for Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.