In my Android Application, there are consistent and frequent server request and responses. If I launch the app with WiFi, then exit and relaunch with 3G. The request to Server fails with IO Exception.
Observations: This happens only on few WiFi ranges. It works perfectly fine at my home during WiFi-3G transition. Both the WiFi s (Home and Office) use WPA/WPA2 security protocols but exhibit different behaviout. I even tried to create a new socket when IO exception happend, but it did not help. But it works fine after 10-15 mins. App automatically connects to the right network and the app launches !!
What could be the issue here ?
Here is a snippet of code
public String readFromUrl(String urlString) {
try {
URL url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
while ((line = in.readLine()) != null)
output.append(line);
return output;
} catch (IOException e) {
e.printStackTrace();
}
}
It fails with exception :
java.net.SocketTimeoutException: Connection timed out
W/System.err( 2615): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
W/System.err( 2615): at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
W/System.err( 2615): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:204)
W/System.err( 2615): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
W/System.err( 2615): at java.net.Socket.connect(Socket.java:1002)
W/System.err( 2615): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
W/System.err( 2615): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)