nanohttpd: streaming big files over http with nanohttpd can cause java.net.SocketException - special handling needed
Hi All,
I am new to NanoHttpd. I am using this to stream a video in Android. For just normal playing this works like a charm without any issue. But when I try to seek to different time in the VideoPlayer, immediatly I get the following error and it creates a different socket and resumes to play after some time. But it shows the progress indicator for long time, which I think because of this issue and re-connecting with different socket. And Streaming is from local network server.
java.net.SocketException: sendto failed: EPIPE (Broken pipe)
at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:546)
at libcore.io.IoBridge.sendto(IoBridge.java:515)
at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504)
at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37)
at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266)
at me.etrmntonwheels.surfacetest.NanoHTTPD$Response.sendBody(NanoHTTPD.java:1423)
at me.etrmntonwheels.surfacetest.NanoHTTPD$Response.sendBodyWithCorrectEncoding(NanoHTTPD.java:1396)
at me.etrmntonwheels.surfacetest.NanoHTTPD$Response.sendBodyWithCorrectTransferAndEncoding(NanoHTTPD.java:1386)
at me.etrmntonwheels.surfacetest.NanoHTTPD$Response.send(NanoHTTPD.java:1371)
at me.etrmntonwheels.surfacetest.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:794)
at me.etrmntonwheels.surfacetest.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:195)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: sendto failed: EPIPE (Broken pipe)
at libcore.io.Posix.sendtoBytes(Native Method)
at libcore.io.Posix.sendto(Posix.java:206)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278)
at libcore.io.IoBridge.sendto(IoBridge.java:513)
at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504)
at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37)
at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266)
at me.etrmntonwheels.surfacetest.NanoHTTPD$Response.sendBody(NanoHTTPD.java:1423)
at me.etrmntonwheels.surfacetest.NanoHTTPD$Response.sendBodyWithCorrectEncoding(NanoHTTPD.java:1396)
at me.etrmntonwheels.surfacetest.NanoHTTPD$Response.sendBodyWithCorrectTransferAndEncoding(NanoHTTPD.java:1386)
at me.etrmntonwheels.surfacetest.NanoHTTPD$Response.send(NanoHTTPD.java:1371)
at me.etrmntonwheels.surfacetest.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:794)
at me.etrmntonwheels.surfacetest.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:195)
at java.lang.Thread.run(Thread.java:818)
I am using serveFile function from SimpleWebServer sample to achieve partial content or streaming. I have read different articles and googled through stackoverflow but still could not figure out the reason.I am stuck at this issue from long time. Please help me to resolve this issue.
About this issue
- Original URL
- State: open
- Created 9 years ago
- Comments: 36 (8 by maintainers)
One more workaround is to add try-catch block to the “sendBody” method, so it closes the connection to the client if the client can’t accept data
@OLEG4120 I used master version of NanoHTTPD (not 2.3.1), and it seems it doesn’t have this problem.
let me post some logs , with the code that i am using on Android 7.0 it might help you.
this code works fine , the file plays and i can seek to different location.but this error shows in console and nothing happens to playback.
now i want to transfer files in 1MB chunks , i used this endAt=startFrom+1000000;
and everything works fine with VLC (no broken pipe error), but with MXPlayer it shows the same error and stops the stream.
`
`
----------------log--------------------
log.txt
Great! I will repeat the code here for the record. we should find a way to integrate this in the nano code.