Android Http server and broken pipes
Asked Answered
T

1

8

I'm trying to develop an Android UPnP application that has an embedded http server in it, so it can serve media files from the device over lan.

The first implementacion of the web server that I used was based on the ElementalHttpServer example from Apache HttpCore http://hc.apache.org/httpcomponents-core-ga/index.html. It had to be changed a little bit because the org.apache.http elements that are already included in the Android library differed from the latest included in the httpCore jar.

I tried to substitute the Android ones with the ones from the jar but that couldn't be done - the ones in the Android library have the priority. When I change the library order there was a problem with duplicate classes.

Than instead of the jars I included source code and change the packet names to avoid duplicated classes problem.

The problem with the broken pipe and connection problems persisted.

I've also tried the NHttpServer from HttpCoreNIO since it has different set of classes than the basic httpCore and could be included and used without conflicting with the httpCore in the Android itself.

Then I used NanoHTTPD which seems to work the best of all the http servers so fat but is still troubled by the same problem as all the others:

java.net.SocketException: The connection was reset
at org.apache.harmony.luni.platform.OSNetworkSystem.sendStreamImpl(Native Method)
at org.apache.harmony.luni.platform.OSNetworkSystem.sendStream(OSNetworkSystem.java:498)
at org.apache.harmony.luni.net.PlainSocketImpl.write(PlainSocketImpl.java:585)
at org.apache.harmony.luni.net.SocketOutputStream.write(SocketOutputStream.java:59)
at com.zappotv.network.http.NanoHTTPD$HTTPSession.sendResponse(NanoHTTPD.java:828)
at com.zappotv.network.http.NanoHTTPD$HTTPSession.run(NanoHTTPD.java:478)
at java.lang.Thread.run(Thread.java:1096)

and

java.net.SocketException: Broken pipe
at org.apache.harmony.luni.platform.OSNetworkSystem.sendStreamImpl(Native Method)
at org.apache.harmony.luni.platform.OSNetworkSystem.sendStream(OSNetworkSystem.java:498)
at org.apache.harmony.luni.net.PlainSocketImpl.write(PlainSocketImpl.java:585)
at org.apache.harmony.luni.net.SocketOutputStream.write(SocketOutputStream.java:59)
at com.zappotv.network.http.NanoHTTPD$HTTPSession.sendResponse(NanoHTTPD.java:828)
at com.zappotv.network.http.NanoHTTPD$HTTPSession.run(NanoHTTPD.java:478)
at java.lang.Thread.run(Thread.java:1096)

Recently I have implemented iJetty into the app but the problem still persists. Sometimes the requesting device goes into an endless loop of requests.

What could I be doing wrong? May the headers be a problem ?

Toreutics answered 1/8, 2011 at 12:5 Comment(2)
Does this happen immediately even for small transfers, or only after some time / volume of data?Bunin
Experiencing the same thing with Nanohttpd in 2020. Happens after I try to resume downloading a file (content-range).Gala
M
0

Can't say much about the errors without seeing your code.. but I've needed a HTTP server before and used the NPR app as an example to work off. The code is fairly straight forward example of how to use java.net.ServerSocket.

http://code.google.com/p/npr-android-app/source/browse/Npr/src/org/npr/android/news/StreamProxy.java

Misdemeanor answered 7/1, 2012 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.