Last active
August 29, 2015 14:02
-
-
Save hitsujiwool/ea8feff5b2f7bfee2190 to your computer and use it in GitHub Desktop.
WebSocket on Play2.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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