开发者

Java RMI : connection refused

开发者 https://www.devze.com 2023-02-12 14:57 出处:网络
I have written following code for the client of RMI. But getting jav开发者_如何学Goa.rmi.ConnectException: Connection refused to host: localhost; nested

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

jav开发者_如何学Goa.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.


I met the same problem. It's silly but just that I forgot to start the RMI registry process.

So, you also need to run RMI Registry process

rmiregistry 

Before you try to rebind(address, obj) with RMI registry.

0

精彩评论

暂无评论...
验证码 换一张
取 消