RMI 表中没有此类对象,服务器通信错误

发布于 2024-08-29 09:54:05 字数 1756 浏览 1 评论 0原文

我的目标是创建一个同时启动服务器和客户端的分布式计算程序。我需要它能够安装在几台机器上,并使所有机器相互通信,即主节点和 5 个从节点都来自一个应用程序。

我的问题是我无法正确使用 unicastRef,我认为这是在同一端口上启动所有内容的问题,是否有更好的方法我忽略?

这是我代码的一部分(重要的部分)

try {

        RMIServer obj = new RMIServer();
        obj.start(5225);

    } catch (Exception e) {
       e.printStackTrace();

    }


      try {
            System.out.println("We are slave's ");
            Registry rr = LocateRegistry.getRegistry("127.0.0.1", Store.PORT, new RClient());

            Call ss = (Call) rr.lookup("FILLER");

            System.out.println(ss.getHello());

        } catch (Exception e) {
            e.printStackTrace();
        }
}

这是我的主类(上面)

这是服务器类(下面)

public RMIServer() { 我

    public void start(int port) throws Exception {

        try {

            Registry registry = LocateRegistry.createRegistry(port, new RClient(), new RServer());

            Call stuff = new Call();

            registry.bind("FILLER", stuff);

            System.out.println("Server ready");
        } catch (Exception e) {
            System.err.println("Server exception: " + e.toString());
            e.printStackTrace();
        }
    }

不知道我错过了什么或我忽略了什么,但输出看起来像这样。

收听5225 收听8776 服务器准备就绪 我们是奴隶 收听8776 java.rmi.NoSuchObjectException:表中没有这样的对象 在 sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) 在 sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233) 在 sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359) 在 sun.rmi.registry.RegistryImpl_Stub.lookup(来源未知) 在 Main.main(Main.java:62)

第 62 行是这样的 ::: Call ss = (Call) rr.lookup("FILLER");

My goal is to create a Distributed computing program that launches a server and client at the same time. I need it to be able to install on a couple of machines and have all the machines communicating with each other, i.e. Master node and 5 slave nodes all from one application.

My problem is that I cannot properly use unicastRef, I'm thinking that it is a problem with launching everything on the same port, is there a better way I am overlooking?

this is part of my code (the part that matters)

try {

        RMIServer obj = new RMIServer();
        obj.start(5225);

    } catch (Exception e) {
       e.printStackTrace();

    }


      try {
            System.out.println("We are slave's ");
            Registry rr = LocateRegistry.getRegistry("127.0.0.1", Store.PORT, new RClient());

            Call ss = (Call) rr.lookup("FILLER");

            System.out.println(ss.getHello());

        } catch (Exception e) {
            e.printStackTrace();
        }
}

this is my main class (above)

this is the server class (below)

public RMIServer() {
}

    public void start(int port) throws Exception {

        try {

            Registry registry = LocateRegistry.createRegistry(port, new RClient(), new RServer());

            Call stuff = new Call();

            registry.bind("FILLER", stuff);

            System.out.println("Server ready");
        } catch (Exception e) {
            System.err.println("Server exception: " + e.toString());
            e.printStackTrace();
        }
    }

I don't know what I am missing or what I am overlooking but the output looks like this.

Listen on 5225
Listen on 8776
Server ready
We are slave's
Listen on 8776
java.rmi.NoSuchObjectException: no such object in table
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at Main.main(Main.java:62)

line 62 is this ::: Call ss = (Call) rr.lookup("FILLER");

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

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

发布评论

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

评论(1

傻比既视感 2024-09-05 09:54:05

也许是因为您对服务器类中存根的引用是 try 块本地的,并且该引用之后立即被垃圾收集。尝试将 stuff 改为类变量。

Maybe it's because your reference to the stub in your server class is local to the try block and the reference is immediately garbage collected after. Try making stuff a class variable instead.

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