Android : Socket - java.net.SocketException: sendto failed: EPIPE (Broken pipe)

隐身守侯 提交于 2019-11-27 14:47:15

The peer closed the connection while you were writing to it. That usually means you sent it something it didn't understand. Is it perhaps an HTTP server? Or some other protocol that you haven't implemented in your client code?

Felix

My two cents: we had the same issue (BROKEN EPIPE), and looking through Fiddler (or Charls, or WireShark, or other proxy debugger / listener / etc) we've noticed that no request gets sent out at all.

The reason was that we added "Content-Length" header with the wrong value.

I met this kind issue on a Samsung Tablet(GT-P5113, Android 4.2.2) device, the application works well on other devices(Nexus 4/5/7).

The code in the Libcore/io/IoBridge.java looks like :

public static int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws IOException {
    boolean isDatagram = (inetAddress != null);
    if (!isDatagram && byteCount <= 0) {
        return 0;
    }
    int result;
    try {
        result = Libcore.os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port);
    } catch (ErrnoException errnoException) {
        result = maybeThrowAfterSendto(isDatagram, errnoException);
    }
    return result;
}

while the Libcore.os.sendto() is a native call.

Maybe try one more time is a good candidate for workaround.

Happened to me too, and the silly reason was that the Internet on the device was not working properly.

Check your internet connection, this could be the reason.

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