Possible Duplicate:
Socket gets stuck when doing readLine()
I wrote jar library and want to use it in my android project. Here one important method from this library:
private static String convertStreamToString(InputStream is) {
/* is - it's the inputStream created from server response entity.
I use org.apache.http classes to communicate with server. */
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) { // <-- this line
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
If I use my library to build java applets and run it on a PC - this code works greate.
But if I use it in Android application and run it on emulator or device, it can stucks sometimes (not always!) for a very long time on a marked line. So SockedTimeoutExceptions happens in this case.
So, I would like to know the reason. And it would be greate if you will help me to get rid from this problem.