远程参与者仅在本地主机上工作
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 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?
您可以在客户端和服务器代码的开头添加“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.