java rmi无法正常工作

时间:2015-07-27 01:50:15

标签: java eclipse rmi

我使用eclipse ide在java代码中创建了一个rmi。我已经在3阶段创建了它,但抛出了一些错误。任何可以帮助我。我的所有代码和错误都在下面给出

第一个代码是一个远程扩展的接口。第二个代码是实现myremote的类,第三个代码是调用所有代码的客户端类。

 1- MyRemote.java





  public interface MyRemote extends Remote {

  public String sayHello() throws RemoteException;

}

   2- MyRemoteImpl.java





     public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote{



public String sayHello() {

    return "Server say, 'Hello'";
}

public MyRemoteImpl() throws RemoteException{

}

public static void main(String[] args) {

    try {

        MyRemote service = new MyRemoteImpl();
        Naming.rebind("RemoteHello", service);

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

}

3- MyRemoteClient.java




    public class MyRemoteClient {
      public static void main(String[] args) {

    new MyRemoteClient().go();
}

public void go() {

    try {

        MyRemote service = (MyRemote)  Naming.lookup("rmi://127.0.0.1/RemoteHello");
        String s = service.sayHello();
        System.out.println(s);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

}

错误是:

  1-    



   java.rmi.ConnectException: Connection refused to host: 192.168.8.102; nested exception is: 
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at rmi.MyRemoteImpl.main(MyRemoteImpl.java:25)
 Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
... 7 more


   2- 




    java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested           exception is: 
   java.net.ConnectException: Connection refused: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
     at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at rmi.MyRemoteClient.go(MyRemoteClient.java:15)
at rmi.MyRemoteClient.main(MyRemoteClient.java:8)
  Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
... 8 more

0 个答案:

没有答案