Java RMI:连接被拒绝 [英] Java RMI : connection refused

查看:217
本文介绍了Java RMI:连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为RMI的客户编写了以下代码。但是获取

I have written following code for the client of RMI. But getting

java.rmi.ConnectException: Connection refused to host: localhost; nested 
exception is:
    java.net.ConnectException: Connection refused: connect

代码:

import java.rmi.*;
import java.net.*;
import java.rmi.registry.*;

class client
{
    public static void main(String [] ars)
    {
        Iface serv;
        Registry r;
        String serveraddr = ars[0];
        String serverport = ars[1];
        String text = "Hey jude";

        System.out.println("Sending" + text);

        try{
            r = LocateRegistry.getRegistry(
            serveraddr,
            (new Integer(serverport)).intValue()
            );
            serv = (Iface) r.lookup("rmi://server");

            serv.receive(text);
        }
        catch(Exception e){
            System.out.println(e);
        }
    }   
}


推荐答案

如果您在绑定,重新绑定或查找时获得该选项,则注册表未运行。如果您进行远程调用,请参阅 RMI FAQ ,如果您运行Linux,还要检查/ etc / hosts文件是否将127.0.0.1映射到localhost,将您的真实IP地址映射到您的真实主机名 - 这是一个某些Linux发行版中常见的问题。

If you're getting that on bind, rebind, or lookup, the Registry isn't running. If you get it doing the remote call, see item A.1 in the RMI FAQ supplied with the Javadoc, and if you're running Linux also check that your /etc/hosts file maps 127.0.0.1 to localhost and your real ip address to your real hostname - this has been a common problem in some Linux distributions.

这篇关于Java RMI:连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆