EPIPE (Broken pipe) while uploading?

坚强是说给别人听的谎言 提交于 2019-12-01 07:46:01

'Broken pipe' means you have written to a connection that has already been closed by the peer.

Probably you have exceeded an upload size limit.

You should also note that your use of available() is invalid. There is a specific warning in the Javadoc about not using it the way you are using it. You don't need it anyway:

while ((count = in.read(buffer)) > 0)
{
  out.write(buffer, 0, count);
}

where buffer is any reasonable size, e.g. 8192 bytes.

I had a similar problem using HttpURLConnection. Just add:

conn.setRequestProperty("connection", "close"); // disables Keep Alive

to your connection or disable it for all connections:

System.setProperty("http.keepAlive", "false");

From the API about disconnect():

Releases this connection so that its resources may be either reused or closed. Unlike other Java implementations, this will not necessarily close socket connections that can be reused. You can disable all connection reuse by setting the http.keepAlive system property to false before issuing any HTTP requests.

So, Android will reuse the old socket connection. Disabling it with the code above you can fix it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!