Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Play 2.0 WebSocket request header not found

I am trying to do a very simple proof of concept using Play 2.0 websockets.

Here is what I am doing right now:

  • Defining the WebSocket in my controller:
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)
}
  • Add the route in my routes file
GET     /wsrequest                  controllers.Application.wsrequest

  • Use the following inside the javascript in my index.scala.html:

var sock = new WS("@routes.Application.wsrequest().webSocketURL()")

However when I try and compile this I get an error:


[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


Am I missing a step ? Or I have I made a mistake in what I have done above?

like image 975
Apple Pie Avatar asked Feb 04 '13 23:02

Apple Pie


1 Answers

Your template needs an implicit request header, like this:

@(message: String)(implicit request: RequestHeader)
like image 183
Marius Soutier Avatar answered Oct 01 '22 11:10

Marius Soutier