This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes SocketException:socket closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "SocketException:socket closed" Watch "SocketException:socket closed" New topic

SocketException:socket closed

Nimish Patel
Ranch Hand

Joined: Jun 29, 2005
Posts: 84
I am using HttpClient API.I have pasted part of some code below.
I am getting this SocketException:socket closed on "client.executeMethod(getMethod)".How can I handle this exception ? Could you please help me ?

HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod(url);
startTime = System.currentTimeMillis();
byte[] responseBody = null;
String response = null;

try {
int statusCode = client.executeMethod(getMethod);
catch(Exception e) {

I would be really greatful for it.Thanks....

Nimish PATEL
Nimish Patel
Ranch Hand

Joined: Jun 29, 2005
Posts: 84
Please help me.What is cause of socket closed exception ???
Joe Ess

Joined: Oct 29, 2001
Posts: 8843

I tried your code, what there is of it, and it works fine.
according to the HttpClient Documentation:
Transport exceptions are those caused by input/output failures such as an unreliable connection or an inability to complete the execution of an HTTP method within the given time constraint (socket timeout). Generally transport exceptions are non-fatal and may be recovered from by retrying the failed method. . .
Generic transport exceptions in HttpClient are represented by the standard Java class or its sub classes such as and

So it sounds as if HttpClient can't connect to the URL you are specifying. Can you connect with a browser? Can you use HttpClient on other URL's? Have you tried reading the User's Guide (especially the troubleshooting guide), the Wiki and the mailing lists?

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

Joined: Jun 29, 2005
Posts: 84
Thanks a lot for your giving valuable time.I will greatful for it.

I can access this site using browser.It is intranet site.It is working fine in browser.Other sites,It is working fine, but only one intranet site,It is giving this exception.Continue last three days I am trying,but I am not successful.I can't understand.

Thanks joe,

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: SocketException:socket closed
Similar Threads
Http Connection
How to access a page with Windows Integrated security?
Trying to figure out why Im getting "cannot be resolved" error
org.apache.commons.httpclient response not getting
Calling IIS web page from java (that is deployed in Weblogic) using Windows security