How to Fix java.net.ConnectException: Connection refused?

How to Fix java.net.ConnectException: Connection refused?

book

Article ID: KB0081966

calendar_today

Updated On:

Products Versions
TIBCO ActiveMatrix BusinessWorks -

Description

Connection refused is a clear case of a client trying to connect on a TCP port but not able to succeed. 
Below are some of the possible reason why java.net.ConnectException: Connection refused comes:
1) Client and Server, either or both of them are not in the network.

2) Server is not running
The second most common reason is the server is down and not running. In that case, also you will get java.net.ConnectException: Connection refused error.

3) The server is running but not listening on the port, a client is trying to connect.
This is another common cause of "java.net.ConnectException: Connection refused", where the server is running but listening on the different port.

4) Firewall is not permitted for host-port combination
Almost every corporate network is protected by firewalls. If you are connecting to some other companies network then you need to raise firewall request from both sides to ensure that they permit each other's IP address and port number. If the firewall is not allowing connection then also you will receive same java.net.ConnectException: Connection refused 

5) Host Port combination is incorrect.

Issue/Introduction

java.net.ConnectException: Connection refused: connect is one of the most common networking exceptions in Java. This error comes when you are working with client-server architecture and trying to make TCP connection from the client to the server.

Environment

All

Resolution

1) First try to ping destination host, if the host is ping-able it means server machine is accessible, there is no issue with network connectivity.
2) Try connecting to server host and port using telnet.