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
.
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");
– igventurelli
Related question (not duplicate): http://answall.com/q/175241/132
– Victor Stafusa
As far as I know
//
from the front of the protocol, that is, your lookup url should bermi://host:[porta]/referenciaRemota
. In addition you will need to prepare the server-side field by giving permissions for access by setting thejava.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.– Anthony Accioly
igorventurelli already tried too and gives the same error
– ADR
Anthony Accioly worked out the way you said it. Vlw guy.
– ADR
Hello ADR, was it just the lookup URL or did you do something else? (I’ll turn the comment into response)
– Anthony Accioly
only the msmo URL, had already tried several ways.. the way you said it worked.. ok
– ADR