Java RMI: connection refused

I wrote the following code for the RMI client. But getting

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

the 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);
        }
    }   
}
+3
source share
2 answers

If you get this on bind, rebind or lookup, the Registry does not work. If you receive a remote call, see Section A.1 in the RMI FAQ supplied with Javadoc, and if you are using Linux also make sure that your / etc / hosts file maps 127.0.0.1 to localhost and your real IP address to your real hostname - this was a common problem on some Linux distributions.

+11
source

I met the same problem. This is stupid, but I just forgot to start the RMI registration process.

So you also need to start the RMI registration process

rmiregistry 

(, obj) RMI.

0

Source: https://habr.com/ru/post/1793621/


All Articles