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.
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.
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.