Why java rmi supports connection to 127.0.1.1. When is ip 192.168.XX?

I have a java rmi application that I just do:

Customer:

Registry registry = LocateRegistry.getRegistry("localhost");
costApi = (CostApi) registry.lookup("server.CostApi");

Everything works fine when I host the server on localhost. When I run the same program on another machine with a local network, 192.168.xx and change to:

Customer:

Registry registry = LocateRegistry.getRegistry("192.168.x.x");
costApi = (CostApi) registry.lookup("server.CostApi");

it no longer works, and it fails with a very strange error:

java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is: 
    java.net.ConnectException: Connection refused
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:129)
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
    at com.sun.proxy.$Proxy0.dataCost(Unknown Source)
    at billing.data.DataBiller.performBilling(DataBiller.java:57)
    at billing.data.DataBiller.consumeMessage(DataBiller.java:46)
    at general.templates.RabbitWorker.run(RabbitWorker.java:124)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)

I am not even trying to connect to 127.0.1.1, but to 192.168.xx, how to solve this? I prefer to use only Java code and not modify my computer with configuration files. I am using linux

+4
source share
2 answers

. /etc/hosts, , :

  • localhost maps to 127.0.0.1

, Linux .

, java.rmi.server.hostname IP-, . , .

IP-, , - InetAddress.getLocalAddress(),, , . java.rmi.server.hostname.

A.1 FAQ FMI, , . lookup(), , .

+7

. - , . , , ( ), - , IP- , (192.168.xx ), , 127.0.0.1. - - JVM IP-, , - ?

UPDATE: JVM RMI java.rmi.server.hostname JVM. . RMI , , ip- , . RMI java.rmi.server.hostname , , , java.rmi.server.hostname ", , , IP-" ". jvm , localhost, 127.0.0.1. , :

System.setProperty( "java.rmi.server.hostname", "192.168.RMIServer.IP" ) ;

, , , , ( , ).

+1

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


All Articles