In my application i have zipped web content. Web content has embedded video in it.
I show the wen content through Android web view. I serve my content through NanoHTTPD Server. I am on Android 4.2.2 and NanoHTTPD's latest version
My server supports partial content handling through range requests. This error comes in the initial call itself i.e. when accept-range response is sent from my server.
Video as ZipInputInflaterStream is sent in response from my server.
Whenever i try to view a video of large size i get this stack trace.
10-03 14:48:28.097: E/NanoHTTPD(9454): java.net.SocketException: sendto failed: ECONNRESET (Connection reset by peer)
10-03 14:48:28.097: E/NanoHTTPD(9454): at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506)
10-03 14:48:28.097: E/NanoHTTPD(9454): at libcore.io.IoBridge.sendto(IoBridge.java:475)
10-03 14:48:28.097: E/NanoHTTPD(9454): at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507)
10-03 14:48:28.097: E/NanoHTTPD(9454): at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
10-03 14:48:28.097: E/NanoHTTPD(9454): at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
10-03 14:48:28.097: E/NanoHTTPD(9454): at test.http.server.NanoHTTPD$Response.sendAsFixedLength(NanoHTTPD.java:806)
10-03 14:48:28.097: E/NanoHTTPD(9454): at test.http.server.NanoHTTPD$Response.send(NanoHTTPD.java:745)
10-03 14:48:28.097: E/NanoHTTPD(9454): at test.http.server.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:1075)
10-03 14:48:28.097: E/NanoHTTPD(9454): at test.http.server.NanoHTTPD$1$1.run(NanoHTTPD.java:211)
10-03 14:48:28.097: E/NanoHTTPD(9454): at java.lang.Thread.run(Thread.java:856)
10-03 14:48:28.097: E/NanoHTTPD(9454): Caused by: libcore.io.ErrnoException: sendto failed: ECONNRESET (Connection reset by peer)
10-03 14:48:28.097: E/NanoHTTPD(9454): at libcore.io.Posix.sendtoBytes(Native Method)
10-03 14:48:28.097: E/NanoHTTPD(9454): at libcore.io.Posix.sendto(Posix.java:151)
10-03 14:48:28.097: E/NanoHTTPD(9454): at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
10-03 14:48:28.097: E/NanoHTTPD(9454): at libcore.io.IoBridge.sendto(IoBridge.java:473)
10-03 14:48:28.097: E/NanoHTTPD(9454): ... 8 more
It seems the client socket in NanoHTTPD gets disconnected. Below is the code of NanoHTTPD which throws this error
private void sendAsFixedLength(OutputStream outputStream, int pending) throws IOException
{
if (requestMethod != Method.HEAD && data != null) {
int BUFFER_SIZE = 16 * 1024;
byte[] buff = new byte[BUFFER_SIZE];
while (pending > 0) {
int read = data.read(buff, 0, ((pending > BUFFER_SIZE) ? BUFFER_SIZE : pending));
if (read <= 0) {
break;
}
outputStream.write(buff, 0, read); //error thrown from here
pending -= read;
}
}
}
outputStream.write throws the above stack trace.
For large file like this after the exception happens the Android media player sends range requests. This works when i extract the file and send the content through FileInputStream.
Question is NanoHTTPD able to read ZipInputInflaterStream for a larger time ?.Even if it reads why client socket gets closed ?
Please note this problem only happens for large videos like for 19 MB. For smaller files like 11 MB it works.
cheers, Saurav