Programmers learn & share
0 votes
55 views

Problem :

Getting bellow error
java.net.connectexception connection timed out no further information
by (6.9k points)   | 55 views

2 Answers

0 votes

Solution :

1) Firstly try to ping the destination host, if the host is pingable it means client and server machine are in the same network.

2)Try to connect to the server host and port using telnet. If you are able to connect it means something is wrong with your client code. Also, by observing telnet output you will come to know whether the server is running or not or server is disconnecting the connection.

3)For a quick fix catch ConnectException in your main try-catch block like bellow:

try {
    // connect, write, and read ...
} catch (ConnectException ce) {  
    System.out.println("You caught a ConnectException.");
} catch (IOException e1) {       
    // TODO Auto-generated catch block
    e1.printStackTrace();
} finally {
by (36.1k points)  
0 votes

Connect is the most common networking exception in java. This error encounter when you are working with client-side architecture and trying to establish a TCP connection from the client to the server.

Reasons:

This is a clear case that client is trying to connect to TCP port but not able to successfully establish. Here are some couple of reasons;

Client and server, either or both are not in-network:

This is possible that both the client and server are not connected to LAN or the internet or any other network.

The server is not running:

The second most common reason is that the server is down. In this case, you also get error java.net.ConnectException. Connection refused error.

The server is not listing to port:

One reason of encounter this error is that the server is running but not listing to any port. It is very hard to figure out this case until you think about it and verify the connection.

Solution:

First, try to a ping destination host, if the host is pingable then it means that client and server machines are pingable.

Try to connect to the server host and port by using telnet. If you can connect then it means that something is wrong with your client mode. By observing telnet output you will come to know that the server is running or not and the server is disconnecting the connection.

I hope this will help to solve your problem.

ago by (1.3k points)  
2,183 questions
2,490 answers
59 comments
241 users