我正在学习如何从另一台机器打电话给一个远程演员。为了模拟两台不同的机器,我有一台主机,另一台是虚拟机(VM)。Network被设置为NAT,因为在这种设置下,我能够从VM中平平主机(我读到它应该设置为Bridge,但是ping命令超时了)。
Host IP: 172.16.104.242
VM IP: 10.0.2.15除此之外,这是主机上RemoteActor.fsx的代码。
#r "nuget: Akka.FSharp"
#r "nuget: Akka.Remote"
open System
open Akka.Actor
open Akka.Configuration
open Akka.FSharp
let config =
Configuration.parse
@"akka {
actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
remote.helios.tcp {
hostname = 172.16.104.242
port = 9001
}
}"
let system = System.create "RemoteFSharp" config
let echoServer =
spawn system "EchoServer"
<| fun mailbox ->
let rec loop() =
actor {
let! message = mailbox.Receive()
let sender = mailbox.Sender()
printfn "echoServer called"
match box message with
| :? string ->
sender <! sprintf "Echo: %s" message
return! loop()
| _ -> failwith "Unknown message"
}
loop()我首先执行这个脚本,这是输出

这是VM上LocalActor.fsx的代码
#r "nuget: Akka.FSharp"
#r "nuget: Akka.Remote"
open System
open Akka.Actor
open Akka.Configuration
open Akka.FSharp
let configuration =
ConfigurationFactory.ParseString(
@"akka {
actor {
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
deployment {
/remoteecho {
remote = ""akka.tcp://RemoteFSharp@172.16.104.242:9001""
}
}
}
remote {
helios.tcp {
port = 0
hostname = 10.0.2.15
}
}
}")
let system = ActorSystem.Create("RemoteFSharp", configuration)
let echoClient = system.ActorSelection("akka.tcp://RemoteFSharp@172.16.104.242:9001/EchoServer")
let task = echoClient <? "F#!"
let response = Async.RunSynchronously (task, 1000)
printfn "Reply from remote %s" (string(response))这是它的输出。

现在,RemoteActor.fsx抛出这个错误

我在Stack溢出上发现了几个帖子,它们都有相同的错误,但却找不出修复方法。显然,错误是因为RemoteActor在Local Actor发送消息之前就死了。同样,在运行RemoteActor.fsx脚本之后,如果我在echoServer <! "Hello"终端中键入这个echoServer <! "Hello",我也会得到相同的错误。
知道怎么解决这个问题吗?任何帮助都将不胜感激!谢谢!
发布于 2020-09-18 01:04:03
更改这一行
let echoClient = system.ActorSelection("akka.tcp://RemoteFSharp@172.16.104.242:9001/EchoServer")至
let echoClient = system.ActorSelection("akka.tcp://RemoteFSharp@172.16.104.242:9001/user/EchoServer")所有用户定义的参与者都存在于/user参与者根下。
https://stackoverflow.com/questions/63912193
复制相似问题