2012-01-19 9 views
0

では動作しません。私はそれがRMIアプリケーションは、LAN

public interface HelloInterface extends Remote { 

    public String say() throws RemoteException; 
} 

public class Hello extends UnicastRemoteObject implements HelloInterface { 

    private String message; 

    public Hello(String msg) throws RemoteException { 
     message = msg; 
    } 

    @Override 
    public String say() throws RemoteException { 
     return message; 
    } 
} 
、次のように私のクラスがあり、働いていない私はLANでそれを実行しようとしたシンプルなRMIアプリケーションを、持っています
public class RmiServer { 

    public static void main(String[] argv) { 
     try { 
      Naming.rebind("Hello", new Hello("Hello, world!")); 
      System.out.println("Hello Server is ready."); 
     } catch (Exception e) { 
      System.out.println("Hello Server failed: " + e); 
     } 
    } 
} 

public class TestRMI { 

    public static void main(String[] argv) { 
     try { 

      HelloInterface hello = (HelloInterface) Naming.lookup("rmi://192.168.*.*/Hello"); 
      System.out.println(hello.say()); 
     } catch (Exception e) { 
      System.out.println("HelloClient exception: " + e); 
     } 

     try { 

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

    } 
} 

LANでこのアプリケーションを動作させるために私を助けてください。

+1

[RMIサーバーの作成](http://docs.oracle.com/javase/tutorial/rmi/server.html)のチュートリアルは読んでいますか? – MockerTim

+0

アプリを実行する前にrmiレジストリを起動しましたか?アプリでプログラムで起動しない場合は、コマンドラインから手動で起動する必要があります。 – MockerTim

答えて

0

ファイアウォールで接続できますか?私はサーバー上のファイアウォールをオフにして、クライアントを接続する必要がありました。