回复不会发送回“客户”角色 [英] Reply is not transmitted back to the 'client'-actor
问题描述
使用远程角色时,我的行为异常。我有一个服务器和一个客户端。客户端向服务器参与者发送消息,服务器回复。当我使用?运算符时,一切都会按预期进行。我从服务器获得了答案。
I've an unexpected behavior when using remote actors. I've a server and a 'client'. The client sends a message to the server actor and the server replies. When I use the '?' operator everything works as expected. I get the answer back from the server.
服务器:
class HelloWorldActor extends Actor {
def receive = {
case msg => self reply (msg + " World")
}
}
object Server extends App{
Actor.remote.start("localhost",2552);
Actor.remote.register("hello-service",Actor.actorOf[HelloWorldActor])
}
客户端:
object Client extends App {
// client code
val actor = remote.actorFor(
"hello-service", "localhost", 2552)
val result = (actor ? "Hello").as[String]
println(result)
}
现在,我更改了代码,以便客户是演员,只是对答案做出反应。但是,不会将回复不发送回客户端。而是在服务器上创建一个 ClientActor实例,并将回复发送到那里?
Now I changed the code so that the client is an actor and just reacts to the answer. However not the reply isn't sent back to the client. Instead a 'ClientActor'-instance is created one the server and the reply is sent there?
修改后的客户端:
class ClientActor extends Actor {
def receive = {
case "Ask" =>{
val actor = remote.actorFor(
"hello-service", "localhost", 2552)
actor ! "Hello"
}
case response:String => println(response) // This executed on the server! That's not what I expect?
}
}
object Client extends App {
// client code
val client = actorOf[ClientActor].start();
client ! "Ask"
}
我想念什么?这是Akka的预期行为吗?以及如何强制它将答案发送回客户?
What am I missing? Is that the expected behavior of Akka? And how can I force it to send the answer back to the client?
感谢您的任何输入。
推荐答案
您尚未开始客户端上的远程处理。
You haven't started the remoting on the client.
这篇关于回复不会发送回“客户”角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!