Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to resolve RMI java.net.NoRouteToHostException

843793Dec 6 2006 — edited Jul 7 2008
Experts please help

I am implementing sample RMi system..

Both client and servers are running in Linux boxes..
I am getting this error when trying to run SampleClient form client
We are using different port 8090 instead of default port

There is a firewall on client server and the port 8090 is opened in firewall
so that client can connect to server at that port

telnet works from client server, telnet 11.252.26.6 8090 gives connected with escape character

ping also works. We afre not able to understand how to debug this issue..

Following are my files

------------------------------------------------------


SampleServer.java

import java.rmi.*;

public interface SampleServer extends Remote
{
public int sum(int a,int b) throws RemoteException;
}


//-----------------------------------------------------------
// File:
SampleServerImpl.java
//-----------------------------------------------------------

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;

public class SampleServerImpl extends UnicastRemoteObject
implements SampleServer
{
SampleServerImpl() throws RemoteException
{
super();
}

public int sum(int a,int b) throws RemoteException
{
return a + b;
}

public static void main(String args[])
{
//set the security manager
try
{
System.setSecurityManager(new RMISecurityManager());

//create a local instance of the object
SampleServerImpl Server = new SampleServerImpl();

//put the local instance in the registry
//Naming.bind("//11.252.26.6:8090/SAMPLE-SERVER" , Server);

Registry reg = LocateRegistry.getRegistry("11.252.26.6",8090);
//Registry reg = LocateRegistry.getRegistry("hostname",8090);

if(reg != null) {
System.out.println("1port="+reg.REGISTRY_PORT);
reg.bind("SAMPLE-SERVER",Server);
System.out.println(" After reg binding server waiting.....");
}
//Naming.rebind("SAMPLE-SERVER!!!" , Server);
System.out.println("Server waiting.....");
}
/*
catch (java.net.MalformedURLException me)
{
System.out.println("Malformed URL: " + me.toString());
me.printStackTrace();
}

*/
catch (RemoteException re)
{
System.out.println("Remote exception: " + re.toString());
re.printStackTrace();
}
catch (Exception exp)
{
System.out.println("Other exception: " + exp.toString());
exp.printStackTrace();
}

}
}

//---------------------------------------------------------------
// File: SampleClient.java
//---------------------------------------------------------------

import java.rmi.*;
import java.rmi.server.*;

public class SampleClient
{
public static void main(String[] args)
{
// set the security manager for the client
System.setSecurityManager(new RMISecurityManager());
//get the remote object from the registry
try
{
System.out.println("Security Manager loaded");
String url = "rmi://11.252.26.6:8090/SAMPLE-SERVER";
//String url = "rmi://hostname:8090/SAMPLE-SERVER";
//change the above port with server IP
SampleServer remoteObject = (SampleServer)Naming.lookup(url);
System.out.println("Got remote object");
System.out.println(" 1 + 2 = " + remoteObject.sum(1,2) );
}
catch (RemoteException exc)
{
System.out.println("Error in lookup: " + exc.toString());
System.out.println("\nnow printing stack trace");
exc.printStackTrace();
}
catch (java.net.MalformedURLException exc)
{
System.out.println("Malformed URL: " + exc.toString());
exc.printStackTrace();
}
catch (java.rmi.NotBoundException exc)
{
System.out.println("NotBound: " + exc.toString());
exc.printStackTrace();
}
}
}



On server side:

rmiregistry 8090&

java -Djava.security.policy=Default.policy -Djava.rmi.server.hostname=11.252.26.6 SampleServerImpl
After reg binding server waiting.....
Server waiting.....



CLient:
-------

java -Djava.security.policy=default.policy SampleClient

Security Manager loaded
Got remote object
Error in lookup: java.rmi.ConnectIOException: Exception creating connection to:
11.252.26.6; nested exception is:
java.net.NoRouteToHostException: No route to host

now printing stack trace
java.rmi.ConnectIOException: Exception creating connection to: 11.252.26.6;
nested exception is:
java.net.NoRouteToHostException: No route to host
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:580)
at
sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:101)
at SampleServerImpl_Stub.sum(Unknown Source)
at SampleClient.main(SampleClient.java:27)
Caused by: java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at
sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFacto
ry.java:22)
at
sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFacto
ry.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
... 5 more
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 4 2008
Added on Dec 6 2006
15 comments
2,331 views