Skip to content

Instantly share code, notes, and snippets.

@hitsujiwool
Last active August 29, 2015 14:02
Show Gist options
  • Save hitsujiwool/ea8feff5b2f7bfee2190 to your computer and use it in GitHub Desktop.
Save hitsujiwool/ea8feff5b2f7bfee2190 to your computer and use it in GitHub Desktop.
WebSocket on Play2.3
package controllers
import play.api.libs.iteratee._
import play.api.mvc._
import play.api.libs.concurrent.Execution.Implicits._
object Application extends Controller {
def ws = WebSocket.using[String] { request =>
val (out, channel) = Concurrent.broadcast[String]
val in = Iteratee.foreach[String] {
msg =>
channel.push(msg);
}
(in, out)
}
def index = Action {
Ok("websocket")
}
}
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index
GET /ws controllers.Application.ws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment