views:

173

answers:

3

I am not able to connect to an remote known server through Java code; the exception while connecting is java.net.NoRouteToHostException: No route to host.

But strangely, I am able to connect to same server through ssh.

Details: Simple Java client when tries to establish connection with Java standalone server, while conneting the exception occurs at following statement:

Socket socket = new Socket(ServerIP ServerPort);

The port needed is open on server so that externally request can come in.

Again the following is returns false

InetAddress.getByName(SERVER_IP).isReachable(1000)

The Server is running on Fedora, Java 5.

FYI: Java cannot resolve DNS address from AIX: UnknownHostException is almost same to my question, but somehow this is not AIX related; moreover I feel the issue to be more of Network or firewall issue.

Please guide me.

A: 

I suggest testing things to narrow down the problem area:

  1. can you telnet to the host/port?
  2. Can Java connect to any other host/port successfully?
  3. Are you using host names or IP addresses - try which ever one you are not using.
  4. Is either computer running a firewall?
hbunny
1 No I cannot telnet the hostIP/port. 2 Yes I am able to connect to other IP in lan. The only remote server is being tried.3 I am using IP address. 4 Yes both machines are using firewall, but server firewall but has allowed listening on specific port, client machine firewall I guess should not be problem as it is creating outgoing connection. netstat -pan | grep 5014 tcp 0 0 :::5014 :::* LISTEN 6212/java
nilesh
If you can't telnet to the host/port then there's something fundamentally broken with the network settings somewhere.
hbunny
Recently I checked, I am able to telnet certain ports (the port on which mysql-cluster is running) ; but not any other such as 5014 mentioned earlier. I even tried to use some other ports but to no use.
nilesh
Either something on your PC is stopping outgoing connections to those ports or something is blocking incoming connections to those ports on the other computer.
hbunny
A: 

Additionally you should also check your .ssh/config file, maybe there is a different Hostname defined for the name you use on the command line.

Bombe
there is no such file in my knowledge, also I have tried connecting through other machines as well, it connected fine.
nilesh
A: 

What about /etc/hosts? Maybe it interferes somehow? Just a guess.

karolrvn