If I run the code snippet as 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
to the IP of the machine where the server is, 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 this question: Java Rmi UnknownHostException .
I tried to run the server according to this post, but even then running my client gives this error UnknownHostException
.