i have developed a application which will post data to server using https. Code works well on devices, now suddenly I'm getting java.net.SocketException : The operation timed out in few devices.
Following is my Code.
public void connectMe() {
httpClient = new DefaultHttpClient();
HttpConnectionParams
.setConnectionTimeout(httpClient.getParams(), 25000);
HttpConnectionParams.setSoTimeout(httpClient.getParams(), 25000);
try {
HttpResponse response = null;
switch (method) {
case GET:
response = httpClient.execute(new HttpGet(url));
break;
case POST:
try {
HttpPost httpPost = new HttpPost(url);
UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(
params, HTTP.UTF_8);
httpPost.setEntity(p_entity);
response = httpClient.execute(httpPost);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
Following is the logcat info
W/System.err( 3593): java.net.SocketException: The operation timed out
W/System.err( 3593): at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
W/System.err( 3593): at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocket(OSNetworkSystem.java:130)
W/System.err( 3593): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:246)
W/System.err( 3593): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
W/System.err( 3593): at java.net.Socket.connect(Socket.java:1074)
W/System.err( 3593): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
W/System.err( 3593): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:153)
W/System.err( 3593): at org.apache开发者_开发问答.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err( 3593): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err( 3593): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
W/System.err( 3593): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err( 3593): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err( 3593): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err( 3593): at com.envision.utils.MyHttpConnection.connectMe(MyHttpConnection.java:128)
i uninstall and reinstalled the application, did't work out got same exception. But after doing factory data reset, above code works in the same mobile and same network.
can anyone please explain me what is happening..? i'm confused..
Thanks.
This looks like a temporary network issue. You could also try going to Flight mode and come back to normal to test again.
精彩评论