Http Android server and broken pipes

I am trying to develop an Android UPnP application that has a built-in HTTP server, so it can serve multimedia files from the device via lan.

The first web server implementation I used was based on the Apache HttpCore ElementalHttpServer example http://hc.apache.org/httpcomponents-core-ga/index.html . It needed to be changed a little, because the org.apache.http elements that are already included in the Android library are different from the last ones included in the httpCore bank.

I tried to substitute Android with those that are in the bank, but this is impossible: those that are in the Android library take precedence. When I change the order of the libraries, there is a problem with repeating classes.

Instead of the boxes, I included the source code and changed the package names to avoid the problem of duplicate classes.

Problem with defective pipes and connection problems persist.

I also tried NHttpServer from HttpCoreNIO, since it has a different set of classes than the base httpCore, and can be enabled and used without conflict with httpCore in Android itself.

Then I used NanoHTTPD, which seems to work better than all HTTP servers so thick, but still worried about the same issue as everyone else:

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) 

I recently implemented iJetty in the application, but the problem still persists. Sometimes the requesting device goes into an endless loop of requests.

What can i do wrong? Can headers be a problem?

+7
source share
1 answer

I can not say much about errors without seeing your code. But before, I needed an HTTP server and I used the NPR application as an example to work. The code is a pretty straight forward example of using java.net.ServerSocket .

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

0
source

All Articles