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();
}
}
“聊天服务器”和“nsource”(其中 nsource 是静态的)是扩展“远程”接口的 UnicastRemoteObject 对象。 (“聊天服务器”和“通知接口”)。
客户端
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
I am trying to develop a simple server/client program usrin java rmi. everything seems to work fine so far, but the only problem is that when a client exits and tries to reconnect i get the following exception:
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
why does the server refused connection the second time?
here is my code
server:
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();
}
}
the "Chat Server" and "nsource" (which nsource is static) are UnicastRemoteObject objects that extend "Remote" Intefaces. ("ChatServer" , and "NotificationInterface").
client
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();
}
}
i am not using rmic since it is not longer required (since java 1.5)
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在查找时得到该信息,则注册表已关闭。如果你让它调用远程方法,那么它的 JVM 已经退出。
If you're getting that on the lookup, the Registry is down. If you get it calling the remote method, its JVM has exited.