Forums Register Login
how to resolve java.net.ConnectException: Connection refused: connect
I want to upload a file with size (>2GB).So i am using applet with servlet to upload it.When i connect applet to servlet using URL class from Java.net which is shown below:-

URL serverUrl=new URL("http://localhost:8084/JFileUpload/TestServlet");
URLConnection connection=serverUrl.openConnection();

i am getting exception when executing the line shown below:-
DataOutputStream outStream=new DataOutputStream(connection.getOutputStream());

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:231)
at sun.net.www.http.HttpClient.New(HttpClient.java:304)
at sun.net.www.http.HttpClient.New(HttpClient.java:321)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:813)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:765)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:690)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:857)

Please help me to resolve this issue.I am using netbeans IDE6.0 & Tomcat server

[ June 10, 2008: Message edited by: elay Raja ]
[ June 10, 2008: Message edited by: elay Raja ]
Welcome to the JavaRanch.

This exception usually means that there is no service listening to the port you are attempting to connect to. Can you load this URL in your web browser:
If you are using Tomcat, you should get a Tomcat welcome screen.
Hi All,

I am having a similar problem.

I have an application running on Websphere 7 Dev environment
And also on my localhost system

I am trying to access a URL like below
http://appl.company.com/SiteContent/a.html from the above application

It works perfectly fine on my local system.

But on the development environment, on this particular line :-
String stream = (new java.net.URL(url)).openStream();
I am getting a "java.net.ConnectException: Connection refused" exception

On googling i figured, such problems are either due to one of the following
- The port is wrong (cannot be this option, as same url running perfectly from local system)
- Firewall is stopping it.

Darshan Shroff
This was basically a firewall issue. Had to do a port opening from the app server to web server by contacting our Network team.

Darshan Shroff
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Feb 27, 2017 23:48:04.