File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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

elay Raja
Greenhorn

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();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-type","application/octet-stream");

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
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

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:
http://localhost:8084/
If you are using Tomcat, you should get a Tomcat welcome screen.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Darshan Shroff
Greenhorn

Joined: Nov 25, 2009
Posts: 12

Hi All,

I am having a similar problem.

I have an application running on Websphere 7 Dev environment
http://appl.company.com/appl/home.action
And also on my localhost system
http://localhost/appl/home.action

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.

Regards,
Darshan Shroff
shroffdarshan@gmail.com
Darshan Shroff
Greenhorn

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.

Regards,
Darshan Shroff
shroffdarshan@gmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to resolve java.net.ConnectException: Connection refused: connect