0
我正在尝试开发一个简单的服务器/客户端程序usrin java rmi。一切似乎都做工精细,到目前为止,但唯一的问题是,当一个客户端退出,并尝试重新连接我得到以下异常: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();
}
}
的 “聊天服务器” 和 “n源”(其中n源是静态的)是扩展 “远程” Intefaces的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)
THX
任何人都可以帮忙吗? – wahtever 2011-04-28 13:34:47