Call WebService in Android to throw connection reset by peer exception

Source: Internet
Author: User
Tags posix connection reset

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).


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.