使用NotBoundException的本地网络上的RMI - 调用“lookup”后出现异常

时间:2012-12-09 21:05:57

标签: java rmi

我在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-Server看起来像这样:

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

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

但是在客户端的查找行中我得到了一个例外:

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)

有人知道如何解决这个问题吗? :) THX

2 个答案:

答案 0 :(得分:2)

尝试更改

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

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

答案 1 :(得分:0)

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

我使用Eclipse-Plugin:genady

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

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

多数民众赞成。 谢谢你的帮助:)