java.rmi.ConnectException: Connection refused to host: 127.0.1.1;

前端 未结 14 2580
攒了一身酷
攒了一身酷 2020-11-27 15:08
    java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
    java.net.ConnectException: Connection refused
    at sun.rmi.transport         


        
相关标签:
14条回答
  • 2020-11-27 15:28

    When I got the same error on my machine ("connection is refused"), the reason was that I had defined the following on the server side:

     Naming.rebind("rmi://localhost:8080/AddService"
       ,addService); 
    

    Thus the server binds both the IP = 127.0.0.1 and the port 8080.

    But on the client side I had used:

    AddServerInterface st = (AddServerInterface)Naming.lookup("rmi://localhost"
                            +"/AddService");
    

    Thus I forgot to add the port number after the localhost, so I rewrote the above command and added the port number 8080 as follows:

    AddServerInterface st = (AddServerInterface)Naming.lookup("rmi://localhost:8080"
                            +"/AddService");
    

    and everything worked fine.

    0 讨论(0)
  • 2020-11-27 15:30

    you can use LocalRegistry such as:

    Registry rgsty = LocateRegistry.createRegistry(1888);
    rgsty.rebind("hello", hello);
    
    0 讨论(0)
  • 2020-11-27 15:33

    On Windows make sure your Windows firewall is correctly configure / disabled. I had to disable the Windows firewall (because I didn't bother with configuring it) to get things to work even when I was testing with localhost.

    0 讨论(0)
  • 2020-11-27 15:38

    In my case I was unable to edit the hosts file because using a pc from the university.

    I fixed the problem running rmiregistry in another port (instead of 1099) with:

    rmiregistry <port>
    

    and then running the server on that port.

    It was basically an error caused by occupied port.

    0 讨论(0)
  • 2020-11-27 15:39

    Simply you can use:

    on server side:

    Registry <objectName1> =LocateRegisty.createRegistry(1099);
    Registry <objectName2> =LocateRegisty.getRegistry();
    

    on Client Side:

    Registry <object name you want> =LocateRegisty.getRegistry();
    
    0 讨论(0)
  • 2020-11-27 15:40

    If you're running in a Linux environment, open the file /etc/hosts.allow add the following line

    ALL
    

    Wildcards

    Also check the /etc/hostname and /etc/host to see if there might be something wrong there.

    I had to change my / etc / host from

    127.0.0.1 localhost
    127.0.1.1 AMK
    

    to

    127.0.0.1 localhost
    127.0.0.1 AMK
    

    also wrote in ALL in the file /etc/hosts.allow which was previously completely empty

    Now everything works

    do not know how safe it is. you have to read more about possible options for /etc/hosts.allow to do something that requires a touch of security.

    0 讨论(0)
提交回复
热议问题