Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我在 Android中有一个HTTP服务器.我为每个HTTP请求创建一个新线程,如上所述: http://hc.apache.org/httpcomponents-core-ga/httpcore/examples/org/apache/http/examples/ElementalHttpServer.java. 当我发出多个GET请求时,有时我会收到如下异常: 01-22 10:28:22.7 我在 Android中有一个http服务器.我为每个http请求创建一个新线程,如上所述:

http://hc.apache.org/httpcomponents-core-ga/httpcore/examples/org/apache/http/examples/ElementalHttpServer.java.

当我发出多个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
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(null);        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();        }                   }    }}
0(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

我不确定为什么会这样.下面是使用的代码,此异常发生在handleRequest()方法或conn.close()中.

httpContext context = new BasichttpContext(null);context.setAttribute("XXX",this.conn);

知道为什么会这样或者如何解决?

解决方法 当我使用以下代码片段将DefaulthttpServerConnection属性传递给handle()方法时,我没有得到此异常:

在WorkerThread类中,使用以下代码传递DefaulthttpServerConnection连接对象:

(DefaulthttpServerConnection)context.getAttribute("XXX");

在handle()方法中,使用获取连接对象,

[+++]

希望它可以帮到某人!

总结

以上是内存溢出为你收集整理的android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接)全部内容,希望文章能够帮你解决android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接)_app_内存溢出

android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接)

android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接),第1张

概述我在 Android中有一个HTTP服务器.我为每个HTTP请求创建一个新线程,如上所述: http://hc.apache.org/httpcomponents-core-ga/httpcore/examples/org/apache/http/examples/ElementalHttpServer.java. 当我发出多个GET请求时,有时我会收到如下异常: 01-22 10:28:22.7 我在 Android中有一个http服务器.我为每个http请求创建一个新线程,如上所述:

http://hc.apache.org/httpcomponents-core-ga/httpcore/examples/org/apache/http/examples/ElementalHttpServer.java.

当我发出多个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
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(null);        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();        }                   }    }}
0(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

我不确定为什么会这样.下面是使用的代码,此异常发生在handleRequest()方法或conn.close()中.

httpContext context = new BasichttpContext(null);context.setAttribute("XXX",this.conn);

知道为什么会这样或者如何解决?

解决方法 当我使用以下代码片段将DefaulthttpServerConnection属性传递给handle()方法时,我没有得到此异常:

在WorkerThread类中,使用以下代码传递DefaulthttpServerConnection连接对象:

(DefaulthttpServerConnection)context.getAttribute("XXX");

在handle()方法中,使用获取连接对象,

希望它可以帮到某人!

总结

以上是内存溢出为你收集整理的android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接)全部内容,希望文章能够帮你解决android – java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1126845.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存