码迷,mamicode.com
首页 > 编程语言 > 详细

【Java】 java.net.SocketException: recvfrom failed: ECONNRESET

时间:2014-11-21 12:30:07      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:android   style   http   io   ar   color   os   sp   java   

今天碰到了这个异常,错误代码就不贴了,把答案记下。

 

ok, the answer was that it‘s the server‘s fault - it had to close the connection after each request .

it might be that android keeps a pool of connections and use the old one or something like that .

anyway , now it works.

 

EDIT: according to the API of HttpURLConnection , this can be solved on the client side too:

The input and output streams returned by this class are not buffered. Most callers should wrap the returned streams with BufferedInputStream or BufferedOutputStream. Callers that do only bulk reads or writes may omit buffering. When transferring large amounts of data to or from a server, use streams to limit how much data is in memory at once. Unless you need the entire body to be in memory at once, process it as a stream (rather than storing the complete body as a single byte array or string).

To reduce latency, this class may reuse the same underlying Socket for multiple request/response pairs. As a result, HTTP connections may be held open longer than necessary. Calls to disconnect() may return the socket to a pool of connected sockets. This behavior can be disabled by setting the http.keepAlive system property to false before issuing any HTTP requests. The http.maxConnections property may be used to control how many idle connections to each server will be held.

taken from: http//developer.android.com/reference/java/net/HttpURLConnection.html

 

【Java】 java.net.SocketException: recvfrom failed: ECONNRESET

标签:android   style   http   io   ar   color   os   sp   java   

原文地址:http://www.cnblogs.com/cuinidaye/p/4112368.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!