在Scala中的play WebSocket中调用方法 [英] Calling a method in play WebSocket in Scala
问题描述
我是scala,Play框架和Akka的新手.我的功能定义为
I am new to scala, Play framework and Akka. I have function defined as
def socket = WebSocket.accept[String, String] { request =>
ActorFlow.actorRef(out => MyWebSocketActor.props(out))
}
我想从其他类中调用它.我不清楚如何调用此函数,因为我不能通过
This i want to call from other class .I am not clear how to call this function as, i can't call this by
objectName.socket(implict req:RequestHeader)
我正在Play 2.5.3,Scala 2.11.7和Akka 2.4.7中工作.
I am working in Play 2.5.3 , Scala 2.11.7 and Akka 2.4.7 .
它给我错误:'=>' expected, ')' found
推荐答案
我仍然不确定这样做的好处是什么,但我会尽力回答您的问题.
I'm still not sure, what the benefit of that would be, but I'll try to answer your question.
首先,这种(objectName.socket(implict req:RequestHeader)
)并不是您如何调用带有隐式参数的方法(在隐式参数中也有错字).
First of all, this (objectName.socket(implict req:RequestHeader)
) ist not how you call a method with an implicit parameter (also you have a typo there in implicit).
但是正如您已经正确指出的那样,您需要一个隐式的RequestHeader
,因此您只能在Controller
的上下文中调用此方法.
But as you already pointed out correctly, you need an implicit RequestHeader
, so you only can call this method within the context of a Controller
.
def anotherControllerAction = objectName.socket
def anotherControllerAction = objectName.socket
那基本上只是将anotherControllerAction
指向套接字实现.然后,您仍然需要将anotherControllerAction
放入路由文件中.
That would basically just point anotherControllerAction
to the socket implementation. Then you still need to put anotherControllerAction
into your routes file.
您可能想更详细地描述您实际想要实现的目标
这篇关于在Scala中的play WebSocket中调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!