找不到基本的Play 2.0 WebSocket请求标头

App*_*Pie 9 scala websocket playframework-2.0

我正在尝试使用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)
}
Run Code Online (Sandbox Code Playgroud)
  • 在我的路线文件中添加路线
GET     /wsrequest                  controllers.Application.wsrequest

Run Code Online (Sandbox Code Playgroud)
  • 在我的index.scala.html中的javascript中使用以下内容:

var sock = new WS("@routes.Application.wsrequest().webSocketURL()")
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试编译它时,我收到一个错误:


[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
Run Code Online (Sandbox Code Playgroud)


我错过了一步吗?或者我在上面所做的事情上犯了错误?

Mar*_*ier 15

您的模板需要一个隐式请求标头,如下所示:

@(message: String)(implicit request: RequestHeader)
Run Code Online (Sandbox Code Playgroud)