Я пытаюсь разработать простую серверную/клиентскую программу usrin java rmi. пока все работает нормально, но единственная проблема в том, что когда клиент выходит и пытается переподключиться, я получаю следующее исключение:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.ConnectException: Connection refused to host: 192.168.x.y; nested exception is:
java.net.ConnectException: Connection refused: connect
почему сервер отказывается подключаться во второй раз?
вот мой код
сервер:
public static void main(String[] args) {
try {
Naming.rebind("ChatServer", new ChatServerImpl());
Naming.rebind("NotificationSource", nsource);
System.out.println("Chat Server is up and runnning!");
} catch (Exception e) {
System.err.println("Problem!!!!");
e.printStackTrace();
}
}
«Сервер чата» и «nsource» (который nsource является статическим) являются объектами UnicastRemoteObject, которые расширяют «удаленные» интерфейсы. ("ChatServer" и "NotificationInterface").
клиент
public static void main(String[] args) {
String url_ChatServer = "rmi://localhost/ChatServer";
String url_NotificationSource = "rmi://localhost/NotificationSource";
try {
ChatServer cs = (ChatServer) Naming.lookup(url_ChatServer);
NotificationSourceInterface ns = (NotificationSourceInterface) Naming.lookup(url_NotificationSource);
new Thread(new ChatClientImpl(cs,ns)).start();
} catch (Exception e) {
System.err.println("Problem ~Client");
e.printStackTrace();
}
}
я не использую rmic, так как он больше не требуется (начиная с java 1.5)
Спасибо