jQuery in Action, 3rd edition
The moose likes Sockets and Internet Protocols and the fly likes how to resolve java.net.ConnectException: Connection refused: connect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "how to resolve java.net.ConnectException: Connection refused: connect" Watch "how to resolve java.net.ConnectException: Connection refused: connect" New topic

how to resolve java.net.ConnectException: Connection refused: connect

elay Raja

Joined: Jun 10, 2008
Posts: 27
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 ]
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

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.

[How To Ask Questions On JavaRanch]
Darshan Shroff

Joined: Nov 25, 2009
Posts: 12

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
Darshan Shroff

Joined: Nov 25, 2009
Posts: 12

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
I agree. Here's the link: http://aspose.com/file-tools
subject: how to resolve java.net.ConnectException: Connection refused: connect
It's not a secret anymore!