9

我在我的应用程序中遇到了这个问题。它很少见且难以发现。这是一个堆栈:

2012-11-30 08:42:22.745myapp.package.MyCommand is failed.java.net.SocketException: recvfrom failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:542)
at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:252)
at myapp.package.HttpCommand.executeRequest(HttpCommand.java:176)
at myapp.package.HttpCommand.execute(HttpCommand.java:83)
at myapp.package.NetworkService$1.run(NetworkService.java:60)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.ErrnoException: recvfrom failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.recvfromBytes(Native Method)
at libcore.io.Posix.recvfrom(Posix.java:131)
at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
at libcore.io.IoBridge.recvfrom(IoBridge.java:503)
... 26 more

在我的应用程序中,我有一个对服务器执行所有命令的类:

private static final AndroidHttpClient client = AndroidHttpClient.newInstance(TAG);

HttpUriRequest request = getRequest(context);
        HttpResponse response = client.execute(request);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (HttpStatus.SC_OK == statusCode) {
            final String json = EntityUtils.toString(response.getEntity());
            handleResult(json);
            Log.i(TAG, json);
        } else {
            handleError(SERVER_CODE);
        } 

你有什么想法这个问题的原因是什么?

4

2 回答 2

5

当收到“连接超时”错误时,我会寻找:

问候。

于 2012-11-30T11:40:13.813 回答
0

对我来说,这个错误发生在:

  • 应该回复的一方意外关闭了连接。

我的情况:Android 通过端口 8080 上的普通套接字连接到微处理器。问题是 uC 在实际发送“OK”回复之前会关闭连接。在这个 uC(ESP8266)中,发送显然是一个延迟操作。解决方案是注释掉关闭连接的行(这行代码来自以前的版本,没有打算回复)。Rgds。

于 2016-03-08T17:24:18.280 回答