Tag Archives: Java.net.connectexception: con

solve java.net.ConnectException : Connection refused:connect report errors

1. The “java.net.ConnectException: Connection refused: connect” error
2. Causes and solutions:
1) The port number is occupied: kill the process with the port number (generally 8080) and release the port; Shut down the Tomcat server completely, or restart the project.
2) Use the following command to check the maximum number of processes allowed in the server: ulimit -u. If this value is set to a low value, such as 1024, increase it to 131072 or unrestricted with the following value: ulimit-u 131072 or ulimit-u unrestricted.
3) Client and server, either or both of which are not in the network.
they could not connect to the LAN or the Internet or any other network, in this case, Java will be thrown
client “java.net.ConnectException:Connection refused” exception.

means the server is down but not running. In this case, you will also get java.net.ConnectException: connection refused error. You can ping to check if the server is running and listen for ports.
5) The server is running but not listening. The client is trying to connect.
The server is running but is listening on a different port. Verify the configuration. If you are working on a large project and have a tiered configuration file, it may be the default configuration or some other setting that overrides your correct Settings.
6) The host port combination is not allowed to use firewalls
Almost every corporate network is protected by a firewall. If you are connecting to other corporate networks, for example in any electronic trading system, need to raise the firewall
both parties require to ensure they allow each other’s IP addresses and port numbers. If the firewall is not allowed to connect, will also receive the same java.net.ConnectException:Java connection refused to abnormal in application.
7) The host port combination is incorrect.
provides an incorrect host port combination, or an earlier host port combination has changed on the server side. Check the current configuration on both the client and server sides.
8) Incorrect protocol in connection string
TCP is the basis of many high-level protocols, including HTTP, RMI, and so on. By connecting to strings, you need to make sure you pass the correct protocol that the server expects. For example, if the server is exposed, a service that passes through RMI rather than a connection string should start with RMI: //.
above is baidu to find the reason and solution, and I met wrong very low-level: didn’t start Tomcat.
The diagram below:

If Tomcat runs main without starting, it will report the following error:

Then you need to start Tomcat as shown below:

Then you can execute the code: