wood burning stoves*
The moose likes Sockets and Internet Protocols and the fly likes Connection Refused Exception 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 "Connection Refused Exception" Watch "Connection Refused Exception" New topic

Connection Refused Exception

paddy Mahadeva Iyer
Ranch Hand

Joined: Feb 10, 2007
Posts: 63

I am working on a application that tries to send out a message to server . but when the system tries to post to the server it gets the following exception

java.net.ConnectException: Connection refused
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:519)
at java.net.Socket.connect(Socket.java:469)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:382)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:494)
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:316)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:817)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:769)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:694)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:861)

I found that the excption is being triggerd from my code in a line where an attempt to get an outputstream is made with the httpurlconnection object.

Can somebody tell me what are the probable causes of such an exception?
Joe Ess

Joined: Oct 29, 2001
Posts: 8836

The most common causes are a firewall between your server and client or the server is not listening. Can you open the same URL with a browser?

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
paddy Mahadeva Iyer
Ranch Hand

Joined: Feb 10, 2007
Posts: 63
no i cannot!
Joe Ess

Joined: Oct 29, 2001
Posts: 8836

Can you ping the server?
I agree. Here's the link: http://aspose.com/file-tools
subject: Connection Refused Exception
Similar Threads
Tomcat cant recognize "error-page" tag in web.xml
Shut Down a SSL Enabled JBOSS
how to resolve java.net.ConnectException: Connection refused: connect
how to read files from internet