RMIに奇妙な問題があります。まず、私はサーバーを起動し、クライアントを起動しました。初めて、私はクライアントからサーバーに接続することができます。その後、私はクライアントを停止します。そして私はクライアントに再接続しようとします。私は、スタブからメソッドを呼び出すときにサーバーのスタブを取得することができますが、私は "接続が拒否されました"の例外の束を得た。私はファイアウォールを有効にしていません。RMI再接続の問題
サーバー
public Server(String name, int port) {
try {
LocateRegistry.createRegistry(port);
ServerModel server = new ServerModel();
String serverStr = "rmi://localhost:" + port + "/" + name;
Naming.rebind(serverStr, server);
} catch (MalformedURLException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
}
とクライアント
public Client(String serverName, int port) throws RemoteException {
controller = new ClientController();
view = new MainView();
ClientRegistry.setData(ClientConstant.FRONT_CONTROLLER, controller);
try {
String serverStr = "rmi://localhost:" + port + "/" + serverName;
ServerInterface serverStub = (ServerInterface) Naming.lookup(serverStr);
ClientRegistry.setData(ClientConstant.STUB, serverStub);
view.setFrontController(controller);
view.display();
} catch (Exception ex) {
// Show error if server is not available
JOptionPane.showMessageDialog(null, "Server is not available", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
と例外
java.rmi.ServerExceptionを設定するためのコードを設定するための私のコード:のRemoteExceptionが発生しましたサーバースレッド内。ネストされた例外は次のとおりです。 java.rmi.ConnectExceptionが送出:接続をホストすることを拒否:192.168.0.104
あなたの提案を使用してコードに変更を加えましたが、問題はまだ発生しています。私は通常、初めてサーバーに接続することができます。しかし、私はクライアントを終了し、サーバーに再接続しようとすると、私は "接続が拒否されました"例外があります。 –