简体   繁体   English

Java RMI:连接被拒绝

[英]Java RMI : connection refused

I have written following code for the client of RMI. 我已经为RMI的客户端编写了以下代码。 But getting 但是得到

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

code : 代码:

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);
        }
    }   
}

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. 如果让它进行远程调用,请参阅Javadoc附带的RMI FAQ中的项目A.1,如果您正在运行Linux,还请检查/ etc / hosts文件是否将127.0.0.1映射到localhost和您的真实IP地址。到您的真实主机名-在某些Linux发行版中,这一直是一个常见问题。

I met the same problem. 我遇到了同样的问题。 It's silly but just that I forgot to start the RMI registry process. 这很愚蠢,但是我忘了开始RMI注册过程。

So, you also need to run RMI Registry process 因此,您还需要运行RMI Registry进程

rmiregistry 

Before you try to rebind(address, obj) with RMI registry. 在尝试与RMI注册表重新绑定(地址,obj)之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM