Recently I used the WebService in my project, because there was no API for calling WebService directly in Android, I used Ksoap, but I encountered a strange bug in my use:
Once webservice is requested, nothing is done, and after 1 minutes, the following exception is thrown when the webservice is requested again:
06-17 15:11:07.869:w/system.err (10915): Java.net.SocketException:sendto failed:econnreset (Connection reset by Peer)
06-17 15:11:07.879:w/system.err (10915): at Libcore.io.IoBridge.maybeThrowAfterSendto (iobridge.java:510)
06-17 15:11:07.879:w/system.err (10915): at Libcore.io.IoBridge.sendto (iobridge.java:479)
06-17 15:11:07.879:w/system.err (10915): at Java.net.PlainSocketImpl.write (plainsocketimpl.java:508)
06-17 15:11:07.879:w/system.err (10915): at java.net.plainsocketimpl.access$100 (plainsocketimpl.java:46)
06-17 15:11:07.879:w/system.err (10915): at Java.net.plainsocketimpl$plainsocketoutputstream.write ( plainsocketimpl.java:270)
06-17 15:11:07.879:w/system.err (10915): at Java.io.BufferedOutputStream.flushInternal (Bufferedoutputstream.java : 185)
06-17 15:11:07.879:w/system.err (10915): at Java.io.BufferedOutputStream.flush (bufferedoutputstream.java:85)
06-17 15:11:07.879:w/system.err (10915): at Libcore.net.http.FixedLengthOutputStream.flush ( FIXEDLENGTHOUTPUTSTREAM.JAVA:49)
06-17 15:11:07.879:w/system.err (10915): at Org.ksoap2.transport.HttpTransportSE.call (httptransportse.java:188)
06-17 15:11:07.879:w/system.err (10915): at Org.ksoap2.transport.HttpTransportSE.call (httptransportse.java:118)
06-17 15:11:07.879:w/system.err (10915): at Org.ksoap2.transport.HttpTransportSE.call (httptransportse.java:113)
06-17 15:11:07.879:w/system.err (10915): at Com.mycos.mobile.util.WebServiceUtils.getObject (Webserviceutils.java : 144)
06-17 15:11:07.879:w/system.err (10915): at Com.mycos.mobile.util.WebServiceUtils.getString (Webserviceutils.java : 63)
06-17 15:11:07.879:w/system.err (10915): at Com.mycos.mobile.util.webserviceasyncrunner$1.run ( WEBSERVICEASYNCRUNNER.JAVA:38)
06-17 15:11:07.879:w/system.err (10915): caused By:libcore.io.ErrnoException:sendto failed:econnreset (Connection Reset by Peer)
06-17 15:11:07.879:w/system.err (10915): at Libcore.io.Posix.sendtoBytes (Native Method)
06-17 15:11:07.879:w/system.err (10915): at Libcore.io.Posix.sendto (posix.java:151)
06-17 15:11:07.879:w/system.err (10915): at Libcore.io.BlockGuardOs.sendto (blockguardos.java:177)
06-17 15:11:07.879:w/system.err (10915): at Libcore.io.IoBridge.sendto (iobridge.java:477)
06-17 15:11:07.879:w/system.err (10915): ... More
From the stack information, the connection is reset by the server, why the continuous request is not a problem, wait a minute after the request will be reset it?
Think for a long time, can not think of exactly what the problem caused the exception, had to use another way to bypass the exception:
The retry mechanism of the httpclient is simulated, and the retry mechanism is added for the WebService request, and if the java.net.SocketException is thrown, two requests are requested continuously (plus the first, the maximum number of retries is 3).