LoginSignup
6
6

More than 5 years have passed since last update.

【解決済】Play2.xのwebsocketで特定のクライアントにpushする方法

Last updated at Posted at 2012-11-01

掲題の"Play2.xのwebsocketで特定のクライアントに向けてpushする方法"についてご存知の方いらっしゃいましたら、ご教授ください。

どこまでできたか

ドキュメントを参考にして書いたコード(下記記載)で、リクエストを送ったクライアントに向けてpushすること

何ができないか(2つの別の問題を抱えています)

1.リクエストを送ったクライアントではなく、接続している任意のクライアントに向けてpushすること
2.参考にしていたPlay付属のsamples/scala/websocket-chatのソースを読み解くためにplay runを実行したところ、下記のようなエラーが表示され、実行できない

:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
unresolved dependency: org.scala-tools.sbt#sbt_2.9.1;0.12.1: not found
Error during sbt execution: Error retrieving required libraries
(see /usr/local/bin/../Cellar/play/2.0.1/bin/../libexec/framework/sbt/boot/update.log for complete log)
Error: Could not retrieve sbt 0.12.1

環境

Scala 2.9.1
Play 2.0.1
sbt 0.12.1

現在のコード

```scala:ここまでできたpackage controllers

import play.api._
import play.api.mvc._
import play.api.libs.json.Json
import play.api.libs.iteratee._

object Application extends Controller {

def index = Action {
Ok(views.html.index("Your new application is ready."))
}

def websocket = WebSocket.using[String] { request =>

// Log events to the console
val in = Iteratee.foreach[String](println).mapDone { _ =>
  println("Disconnected")
}

// Send a single 'Hello!' message
val out = Enumerator("Hello!")

(in, out)

}
}
```##参考
Playのドキュメントの"Websocket"
http://playdocja.appspot.com/documentation/2.0.3/ScalaWebSockets
Playのドキュメントの"反応的なストリーム処理"
http://playdocja.appspot.com/documentation/2.0.3/Iteratees
Play付属のサンプル"Websocket-chat"
https://github.com/playframework/Play20/tree/master/samples/scala/websocket-chat

以上、よろしくお願い致します。

6
6
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6