我正在学习如何从另一台机器调用远程演员。为了模拟两台不同的机器,我有一台主机,另一台是虚拟机 (VM)。网络适配器设置为,NAT
因为通过此设置,我能够从 VM ping 主机(我读到它应该设置为 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()
这是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))
我在 Stack Overflow 上发现了一些有同样错误但无法解决的帖子。显然错误是因为在发送消息RemoteActor
之前死亡。Local Actor
同样在运行RemoteActor.fsx
脚本后,如果我echoServer <! "Hello"
在RemoteActor
终端中键入它,我也会收到同样的错误。
知道如何解决这个问题吗?任何帮助将不胜感激!谢谢!