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 ?