java rmi重新连接客户端问题

发布于 2024-11-04 00:27:10 字数 1498 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明媚殇 2024-11-11 00:27:10

如果您在查找时得​​到该信息,则注册表已关闭。如果你让它调用远程方法,那么它的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文