学习目的 我试图实施简单的游戏应用,从遥远的行为者那里获得数据。 行为者守则如下:
import akka.actor.{Props, ActorSystem, Actor}
class NumbersServer extends Actor {
var number = 0
protected def receive = {
case next => {
number += 1
number
}
case reset => number = 0
case exit => context.stop(self)
case get => sender ! number
}
}
object Server {
def main(args: Array[String]) {
val system = ActorSystem("ServerSystem")
val server = system.actorOf(Props[NumbersServer], "server")
}
}
I package it into a jar and start it from the command line. If I try to send messages to this actor from a Scala console opened from another window, all works fine. Now I want to get the actor from the Play framework. In the Application
object I define the following method:
def numbers = Action {
Ok(views.html.numbers(Client.actor.path.name))
}
然后在<代码>中 一揽子方案一界定客户目标:
object Client {
import play.api.Play.current
val actor = Akka.system.actorFor("akka://[email protected]:2552/user/server")
}
The numbers.html.scala
file:
@(message: String)
@main("Header") {
<h1>@message</h1>
}
因此,我预计,当我去读127.0.0.1:9000/ numbers
时,我就有了一条通往服务器行为体的道路。 相反,我拿到<代码><h1>deadLetters</h1>。 我做了哪些错误,如何正确做?