9
我正在嘗試使用Play 2.0 websockets做一個非常簡單的概念驗證。Basic Play 2.0 WebSocket請求標頭找不到
下面是我在做什麼現在:
- 定義在我的控制器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
- 使用JavaScript內部下面我index.scala.html:
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
我錯過了一步嗎?或者我在上面所做的事情上犯了錯誤?
一個更一般的說明:請確保你不重新分配「請求」一不希望的方式之前,會使用它。這引起了我的興趣,並導致相同的「找不到任何HTTP請求頭」消息。 –