Play 2.0 websockets を使用して、非常に単純な概念実証を試みています。
これが私が今していることです:
- コントローラーで WebSocket を定義する:
def wsrequest = WebSocket.using[String] { request =>
// Send a single 'Hello!' message
val out = Enumerator("Hello!")
// Just consume and ignore the input
val in = Iteratee.consume[String]()
// tie the in and out values to each other
(in, out)
}
- ルート ファイルにルートを追加する
GET /wsrequest controllers.Application.wsrequest
- index.scala.html の JavaScript 内で次を使用します。
var sock = new WS("@routes.Application.wsrequest().webSocketURL()")
ただし、これをコンパイルしようとすると、エラーが発生します。
[info] Compiling 5 Scala sources and 1 Java source to target\scala-2.9.1\classes...
[error] target\scala-2.9.1\src_managed\main\views\html\index.template.scala:32: Cannot find any HTTP Request Header here
[error] Error occurred in an application involving default arguments.
[error] var sock = new WS(""""),_display_(Seq[Any](/*11.33*/routes/*11.39*/.Application.wsrequest().webSocketURL())),format.raw/*11.78*/("""")
[error] ^
[error] one error found
ステップがありませんか?それとも、私が上で行ったことを間違えましたか?