2013-11-02 39 views
0

我的代碼似乎有一個很大的問題。我得到這個:RMI程序重新綁定錯誤

java.rmi.ConnectException: Connection refused to host: 5.12.78.59; nested exception is: 
    java.net.ConnectException: Connection refused: connect 
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619) 
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216) 
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202) 
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340) 
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) 
    at java.rmi.Naming.rebind(Naming.java:177) 
    at Server.main(Server.java:9) 
Caused by: java.net.ConnectException: Connection refused: connect 
    at java.net.DualStackPlainSocketImpl.connect0(Native Method) 
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) 
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) 
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) 
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) 
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) 
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) 
    at java.net.Socket.connect(Socket.java:579) 
    at java.net.Socket.connect(Socket.java:528) 
    at java.net.Socket.<init>(Socket.java:425) 
    at java.net.Socket.<init>(Socket.java:208) 
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40) 
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146) 
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613) 
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216) 
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202) 
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340) 
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) 
    at java.rmi.Naming.rebind(Naming.java:177) 
    at Server.main(Server.java:9) 
    at __SHELL7.run(__SHELL7.java:6) 
    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:606) 
    at bluej.runtime.ExecServer$3.run(ExecServer.java:725) 

下面的代碼:

public class Server { 
    public static void main(String[] args) throws Exception { 

    Generator Ob = new Generator(); 
    System.out.println("1"); 
    Naming.rebind("rmi:///Ob",Ob); 

    System.out.println("Serverul s-a legat la" + 
         " registrul RMI"); 
    } 
} 

發電機被定義正確但當我做Naming.rebind這一切分崩離析,爲什麼呢?感謝您的幫助。

+0

你初始化了'RMI'註冊表嗎? –

+0

是的,我確實在cmd rmiregistry中做了這個,然後java服務器,我得到了那個錯誤:P。這是你想告訴我的,還是我是白癡? –

回答

0

當您重新綁定時,註冊表不運行。我知道你在上面的評論中說了什麼,但證據毫無疑問。

+0

好吧,以便啓動註冊表然後:我打開CMD,我去D:\ java \ bin啓動註冊表1111,然後我打開服務器。我不是這樣做的嗎? –

+0

'啓動註冊表1111'不啓動RMI註冊表。它啓動了一些名爲'registry'的程序,它可能不存在。如果你把它改成'start rmiregistry'1111,'它會啓動一個註冊表監聽端口1111,這不是Naming.bind()所默認的,所以你的應用程序仍然不能工作。嘗試'啓動rmiregistry'。 – EJP

+0

現在我得到: –