远程参与者仅在本地主机上工作

发布于 2024-11-02 17:23:13 字数 981 浏览 0 评论 0原文

我使用 Scala 的远程 Actor 编写了一个程序。我的第一步是创建一个客户端和一个通过环回(127.0.0.1)进行通信的服务器,它运行良好。当我尝试在同一网络上的两个站之间进行通信时,服务器没有捕获任何内容。我在本地和远程客户端程序之间唯一更改的是服务器的 IP 地址。

这是客户端代码:

case class Post(msg: String)

object Client extends Application {
  val client = new ClientRemote
  client.sendMessage
}

class ClientRemote extends Actor {
  val server = select(Node("127.0.0.1", 9010), 'name) //' or server IP

  def sendMessage(): Unit = {
    server ! Post("Hello!")
  }

  def act() {
    // do something
  }
}

这是服务器代码:

case class Post(msg: String)

object Server extends Application {
  val server = new ServerRemote
  server.start
}

class ServerRemote extends Actor {
  def act() {
    alive(9010)
    println("server is started!")
    register('name, self)                  //' register to port
    loop {
      react {
        case Post(msg) => println(msg)
      }
    }
  }
}

有人知道为什么这些程序不起作用或者有任何关于解决方案的想法吗?

谢谢

I wrote a program using Scala's remote actors. My first step was to create a client and a server who communicate by loopback (127.0.0.1) and it works well. When I try to communicate between two stations on the same network, the server doesn't catch anything. The only thing I changed between local and remote client's program is the server's IP address.

Here is the client code:

case class Post(msg: String)

object Client extends Application {
  val client = new ClientRemote
  client.sendMessage
}

class ClientRemote extends Actor {
  val server = select(Node("127.0.0.1", 9010), 'name) //' or server IP

  def sendMessage(): Unit = {
    server ! Post("Hello!")
  }

  def act() {
    // do something
  }
}

Here is the server code:

case class Post(msg: String)

object Server extends Application {
  val server = new ServerRemote
  server.start
}

class ServerRemote extends Actor {
  def act() {
    alive(9010)
    println("server is started!")
    register('name, self)                  //' register to port
    loop {
      react {
        case Post(msg) => println(msg)
      }
    }
  }
}

Does anybody know why these programs dont' work or any idea about a solution?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我家小可爱 2024-11-09 17:23:13

我对 Java 的了解比对 Scala 的了解更多,但是您的 Post case 类的重复定义是否有可能被类加载器视为不同的类?

I know more about Java than I do Scala, but is it possible that your duplicate definitions of the Post case class are considered different classes by the class-loader?

往日情怀 2024-11-09 17:23:13

您可以在客户端和服务器代码的开头添加“scala.actors.Debug.level = 3”,以获取有关 actor 子系统正在执行的操作的更多信息。例如,这会告诉您消息是否已收到但被丢弃,或者它是否在与您想象的不同的端口上侦听,等等。

You can add "scala.actors.Debug.level = 3" at the beginning of the client and server code to get more information about what the actor sub-system is doing. This will tell you, for example, if the message was received but dropped, or if its listening on a different port than you thought, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文