0

我在 RMI 上遇到问题:

我的 RMI-Client 尝试获取 192.168.1.37 的注册表

Registry registry = LocateRegistry.getRegistry("192.168.1.37",1099);
String[] s = registry.list();
    for( String obj : s ) {
        System.out.println("  " + obj);
    }
IMaster master = (IMaster) registry.lookup ("rmi://192.168.1.37:1099/Master");

我的 RMI 服务器看起来像这样:

Registry registry = LocateRegistry.getRegistry();
IMaster m = new Master(3, 3);
registry.rebind ("Master", m);
System.out.println ("Master Server is ready.");

注册表列表 [String[] s = registry.list();] 知道“主”绑定。这意味着:网络上没有问题并且注册表存在。该对象也已导出。(我为 RMI 使用了一个 Eclipse 插件)。

但是在客户端的查找行中,我遇到了一个异常:

java.rmi.NotBoundException: rmi://192.168.1.37:1099/Master
at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:136)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at philosoper.client.ClientServer.main(ClientServer.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at net.genady.rmi.logger.Runner.main(Runner.java:137)

有谁知道如何解决这个问题?:) 谢谢

4

2 回答 2

2

尝试改变

IMaster master = (IMaster) registry.lookup ("rmi://192.168.1.37:1099/Master");

IMaster master = (IMaster) registry.lookup ("Master");
于 2012-12-09T21:21:39.900 回答
0

服务器不知道自己的 IP。所以你必须通过告诉他你的服务器的ip来启动它。

我使用 Eclipse 插件:genady

所以在eclipse中的服务器上:点击“Run Configurations...”->“RMI VM Properties”并将该IP添加到“java.rmi.server.hostname”

和:

IMaster master = (IMaster) registry.lookup ("Master");

就这样。谢谢你的帮助:)

于 2012-12-09T22:21:25.657 回答