大佬教程收集整理的这篇文章主要介绍了android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我发出多个GET请求时,有时我会收到如下异常:
01-22 10:28:22.779: W/System.err(2019): java.net.socketException: recvfrom Failed: ECONNRESET (Connection reset by peer) 01-22 10:28:22.779: W/System.err(2019): at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:552) 01-22 10:28:22.779: W/System.err(2019): at libcore.io.IoBridge.recvfrom(IoBridge.java:516) 01-22 10:28:22.779: W/System.err(2019): at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488) 01-22 10:28:22.779: W/System.err(2019): at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46) 01-22 10:28:22.784: W/System.err(2019): at java.net.PlainSocketImpl$PlainSockeTinputStream.read(PlainSocketImpl.java:240) 01-22 10:28:22.784: W/System.err(2019): at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103) 01-22 10:28:22.784: W/System.err(2019): at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191) 01-22 10:28:22.784: W/System.err(2019): at org.apache.http.impl.io.httprequestParser.parseHead(httprequestParser.java:71) 01-22 10:28:22.784: W/System.err(2019): at org.apache.http.impl.io.AbstractmessageParser.parse(AbstractmessageParser.java:174) 01-22 10:28:22.784: W/System.err(2019): at org.apache.http.impl.AbstracthttpServerConnection.receiverequestHeader(AbstracthttpServerConnection.java:141) 01-22 10:28:22.784: W/System.err(2019): at org.apache.http.protocol.httpservice.handlerequest(httpservice.java:135) 01-22 10:28:22.784: W/System.err(2019): at com.example.devicecommunication.Connectservice$WorkerThread.run(Connectservice.java:744) 01-22 10:28:22.784: W/System.err(2019): Caused by: libcore.io.ErrnoException: recvfrom Failed: ECONNRESET (Connection reset by peer) 01-22 10:28:22.784: W/System.err(2019): at libcore.io.Posix.recvfromBytes(Native Method) 01-22 10:28:22.784: W/System.err(2019): at libcore.io.Posix.recvfrom(Posix.java:131) 01-22 10:28:22.784: W/System.err(2019): at libcore.io.blockGuardOs.recvfrom(BlockGuardOs.java:164) 01-22 10:28:22.789: W/System.err(2019): at libcore.io.IoBridge.recvfrom(IoBridge.java:513) 01-22 10:28:22.789: W/System.err(2019): ... 10 more@H_944_12@我不确定为什么会这样.下面是使用的代码,此异常发生在handlerequest()方法或conn.close()中.
class WorkerThread extends Thread{ httpservice httpservice; httpServerConnection conn; public WorkerThread(httpservice httpservice,httpServerConnection conn){ super(); this.httpservice = httpservice; this.conn = conn; } public void run(){ httpContext context = new BasichttpContext(@R_450_6633@ try { Log.d(tag,"Going to call Handle request here"); this.httpservice.handlerequest(this.conn,context); } catch (ConnectionClosedException eX) { ex.printStackTrace(); Log.d(tag,"Client closed connection exception"); } catch (IOException eX) { ex.printStackTrace(); Log.d(tag,"I/O exceptionnnnn " + ex.getmessage()); } catch (httpException eX) { Log.d(tag,"Unrecoverable http protocol violation: " + ex.getmessage()); } finally { Log.d(tag,"Inside Finally Block"); try { this.conn.close(); Log.d(tag,"Connection closed successfully"); } catch (IOException E) { // TODO Auto-generated catch block e.printStackTrace(); } } } }@H_944_12@知道为什么会这样或者如何解决?
在WorkerThread类中,使用以下代码传递DefaulthttpServerConnection连接对象:
httpContext context = new BasichttpContext(@R_450_6633@ context.setAttribute("XXX",this.conn);@H_944_12@
(DefaulthttpServerConnection)context.getAttribute("XXX");@H_944_12@希望它可以帮到某人!
以上是大佬教程为你收集整理的android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接)全部内容,希望文章能够帮你解决android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。