我正在尝试连接localhost上的两个远程actor(禁用防火墙),但没有消息通过。我创建了一些简单的代码来传达我的问题:
演员1:
package test
import scala.actors._
import scala.actors.Actor._
import scala.actors.remote._
import scala.actors.remote.RemoteActor._
object Actor1 {
RemoteActor.classLoader = getClass().getClassLoader()
}
class Actor1 extends Actor {
def act {
alive(9000)
register('actor1, self)
println("Actor1 running")
while (true) {
react {
case s: String => {
println("received1: " + s)
sender ! "Server reply"
}
case _ => println("Received wierdness;)")
}
}
}
}
演员2:
package test
import scala.actors._
import scala.actors.Actor._
import scala.actors.remote._
import scala.actors.remote.RemoteActor._
object Actor2 {
RemoteActor.classLoader = getClass().getClassLoader()
}
class Actor2 extends Actor {
val actor1 = select(Node("127.0.0.1", 9000), 'actor1)
def act {
println("Sending message to actor1(" + actor1 + ")")
actor1 ! "Message to server"
println("Actor2 running")
while (true) {
react {
case s: String => println("received2: " + s)
case _ => println("Received wierdness;)")
}
}
}
}
和主要课程:
包裹测试
object Test {
def main(args: Array[String]): Unit = {
val a1 = new Actor1()
val a2 = new Actor2()
println("Starting actors")
a1.start
a2.start
}
}
我做错了什么?感谢您的帮助。