File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes SocketTimedOutException while reading inputStream. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "SocketTimedOutException while reading inputStream." Watch "SocketTimedOutException while reading inputStream." New topic

SocketTimedOutException while reading inputStream.

ashutosh dhiman

Joined: Oct 07, 2008
Posts: 7
I am facing a weird problem. I am writing some code in one eclipse plugin.
Plugin makes a request to server using by writing some data to output stream and reads the returned data from the inputStream.

When it tries to read the data from the inputStream returned by the connection (see code snippet below)

where b is byte. It throws SocketTimedOutExcption.
Now as far as i understand HTTPURLConnection class (may be i am wrong) . It by default has a ReadTimeOut set to 0 (0 means infinite wait here)..
So in my opinion it should wait until unless server returns the response. Also HTTPURLConnection is Synchronous, so it should wait until unless server returns data (within timeout limit).

I put the above code in while loop to retry and after retrying a couple of time it works. By retry i mean i sent my request only once but i retry on reading the inputStream (response from server).

Problem became worst when we noticed that its only replicable ONLY ON install i.e. it dosen't come when i tried debugging it in development enviornemnt.
If you want full code i will paste that here also.. just let me know
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

I'm curious to see why this is happening. I'll try installing the plugin. Can you attach it as a zip?
ashutosh dhiman

Joined: Oct 07, 2008
Posts: 7
Hi, i can not share the plugin. As its my company code and i am bound not to do so, legally.. I am really really sorry for that. Can you tell me how you would have debug it? i mean does taking java dumps or anything like that will help? or you can guide me what should i do.. Thanks for your reply..
I agree. Here's the link:
subject: SocketTimedOutException while reading inputStream.
It's not a secret anymore!