I made a few patches to the example from http://dirkmeister.blogspot.com/2008/12/remote-actors-in-scala.html. It works with Scala 2.7.4RC1 on ubuntu 8.10. Milage may vary.
RemotePongApp must be started first.
RemotePingApp.scala:
package mgm7734 import scala.actors.Actor import scala.actors.Actor._ import scala.actors.Exit import scala.actors.remote.RemoteActor import scala.actors.remote.RemoteActor._ import scala.actors.remote.Node @serializable case object Ping @serializable case object Pong @serializable case object Quit object RemotePingApp { def main(args: Array[String]) : Unit = { val port = 9001 // args(0).toInt val peer = Node("127.0.0.1", 9000) // Node(args(1), args(2).toInt) val ping = new RemotePing(port, peer, 16) ping.start() } } class RemotePing(port: Int, peer: Node, count: Int) extends Actor { trapExit = true // (1) def act() { RemoteActor.classLoader = getClass().getClassLoader() alive(port) // (2) register('Ping, self) // (3) val pong = select(peer, 'Pong) // (4) link(pong) // (5) var pingsLeft = count - 1 pong ! Ping // (6) while (true) { receive { case Pong => Console.println("Ping: pong") if (pingsLeft > 0) { pong ! Ping pingsLeft -= 1 } else { Console.println("Ping: start termination") pong ! Quit // (7) // Terminate ping after Pong exited (by linking) } case Exit(pong, 'normal) => // (8) Console.println("Ping: stop") exit() } } } }
RemotePongApp.scala:
package remote <code> import scala.actors.Actor import scala.actors.Actor._ import scala.actors.remote.RemoteActor import scala.actors.remote.RemoteActor._ object RemotePongApp { def main(args: Array[String]) : Unit = { val port = 9000 // args(0).toInt val pong = new RemotePong(port) pong.start() } } class RemotePong(port: Int) extends Actor { def act() { RemoteActor.classLoader = getClass().getClassLoader() alive(port) register('Pong, self) while (true) { receive { case Ping => Console.println("Pong: ping") sender ! Pong case Quit => Console.println("Pong: stop") exit() // (9) } } } }