RMI application works localhost, but gives error when placing Server IP

Asked

Viewed 330 times

1

If I run the code snippet as it is below in my application, it works:

public static void main(String args[]){
    try {
       final InterfaceTrilha interfaceServer = (InterfaceTrilha) Naming.lookup("//localhost:1070/ServidorTrilha");

But if I change the localhost by the IP of the machine where the server is located, as below:

final InterfaceTrilha interfaceServer = (InterfaceTrilha) Naming.lookup("//rmi://192.168.0.107/ServidorTrilha");

Returns the following error:

java Cliente
java.rmi.UnknownHostException: Unknown host: rmi; nested exception is:
    java.net.UnknownHostException: rmi
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:616)
    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.newCall(UnicastRef.java:342)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Naming.java:101)
    at Cliente.main(Cliente.java:67)
Caused by: java.net.UnknownHostException: rmi
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at java.net.Socket.<init>(Socket.java:434)
    at java.net.Socket.<init>(Socket.java:211)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
    ... 6 more

Server code:

public Servidor() throws RemoteException{
    try{
        server = new Trilha();
        registry = LocateRegistry.createRegistry(1070);
        registry.rebind("ServidorTrilha", server);
        System.out.println("SERVIDOR REGISTRADO COM SUCESSO!")

I saw a similar problem in that question: Java Rmi Unknownhostexception.

I tried to run the server according to that post, but even when running my client gives this error UnknownHostException.

  • 1

    You don’t have to set the port when searching for the server either? final InterfaceTrilha interfaceServer = (InterfaceTrilha) Naming.lookup("//rmi://192.168.0.107:[porta]/ServidorTrilha");

  • Related question (not duplicate): http://answall.com/q/175241/132

  • As far as I know // from the front of the protocol, that is, your lookup url should be rmi://host:[porta]/referenciaRemota. In addition you will need to prepare the server-side field by giving permissions for access by setting the java.rmi.server.hostname (the default is 127.0.0.1), etc., for more details see this reply from Soen. Also ensure that the server port 1070 is reachable on the client side when you raise the server, a firewall may be in the way.

  • igorventurelli already tried too and gives the same error

  • Anthony Accioly worked out the way you said it. Vlw guy.

  • Hello ADR, was it just the lookup URL or did you do something else? (I’ll turn the comment into response)

  • only the msmo URL, had already tried several ways.. the way you said it worked.. ok

Show 2 more comments

1 answer

0


  • It is not necessary to use "//" in front of the rmi protocol declaration.

In the lookup URL: Naming.lookup("//rmi://192.168.0.107/ServidorTrilha");

The right thing would be: Naming.lookup("rmi://192.168.0.107:1070/ServidorTrilha");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.