Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala RemoteActor多个网络接口_Scala_Actor_Remote Actors - Fatal编程技术网

Scala RemoteActor多个网络接口

Scala RemoteActor多个网络接口,scala,actor,remote-actors,Scala,Actor,Remote Actors,RemoteActor中的方法alive(port)未将IP地址作为参数 它在内部构造一个TcpService对象,该对象通过调用Java的InetAddress.getLocalHost().getHostAddress()来分配IP地址,该对象返回第一个可用接口的IP 这会在具有多个网络接口的计算机上造成问题,因为它可能返回错误的IP地址 是否有任何可能的方法来克服这个问题 谢谢。问得好。这取决于您想在解决方案上投资多少。我可以想象两种方式: 1) 更改默认实现的第一种方法是自己编写更好的东

RemoteActor
中的方法
alive(port)
未将IP地址作为参数

它在内部构造一个
TcpService
对象,该对象通过调用Java的
InetAddress.getLocalHost().getHostAddress()
来分配IP地址,该对象返回第一个可用接口的IP

这会在具有多个网络接口的计算机上造成问题,因为它可能返回错误的IP地址

是否有任何可能的方法来克服这个问题


谢谢。

问得好。这取决于您想在解决方案上投资多少。我可以想象两种方式:

1) 更改默认实现的第一种方法是自己编写更好的东西。不过这并不难,因为远程actor库的所有代码都可以在上找到

我的建议是重新实施课程的部分内容,尤其是第73行,类似于:

private val internalNode = {
    val interfaces = NetworkInterface.getNetworkInterfaces()
    val interface  = ... // find the right interface here
    val addresses  = interface.getInetAddresses()
    val address    = ... // find the right address here
    new Node(address, port)
}
如果您想添加或更改其他内容,此方法还允许您自定义其他内容

2) 另一种(可能更简单)方法是避免同时使用默认实现,而是使用非常流行的actor框架。Akka提供了大量的附加功能,但也提高了效率和健壮性。如果查看它们和类,您将看到主机实际上是从全局配置条目“hostname”读取的。 给出了有关如何操作配置的详细指南。您应该能够使用与上面类似的代码来找到正确的接口和地址

希望有帮助