私はHttpService
いくつかのファイルを共有するために Android デバイスとブラウザーに応答を送信するために使用しています。このサービスは Android デバイスで動作します。すべて正常に動作し、ビデオ ファイルを除外します。オンラインで音楽を聴くのは完璧です。しかし、オンライン ビデオを見ようとすると、WebService
以下に示すエラーで失敗します。
java.net.SocketException: sendto failed: EPIPE (Broken pipe)
at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506)
at libcore.io.IoBridge.sendto(IoBridge.java:475)
at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507)
at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
at org.apache.http.impl.io.AbstractSessionOutputBuffer.write(AbstractSessionOutputBuffer.java:109)
at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:113)
at org.apache.http.entity.FileEntity.writeTo(FileEntity.java:83)
at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:97)
at org.apache.http.impl.AbstractHttpServerConnection.sendResponseEntity(AbstractHttpServerConnection.java:182)
at org.apache.http.protocol.HttpService.handleRequest(HttpService.java:209)
at com.test.communication.server.WebServer$1.run(WebServer.java:94)
at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
at libcore.io.Posix.sendtoBytes(Native Method)
at libcore.io.Posix.sendto(Posix.java:146)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
at libcore.io.IoBridge.sendto(IoBridge.java:473)
サーバー側のコード スニペット:
WebServer.java
private BasicHttpProcessor httpproc = null;
private BasicHttpContext httpContext = null;
private HttpService httpService = null;
private HttpRequestHandlerRegistry registry = null;
public WebServer(Context context) {
this.setContext(context);
httpproc = new BasicHttpProcessor();
httpContext = new BasicHttpContext();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
httpService = new HttpService(httpproc,
new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
registry = new HttpRequestHandlerRegistry();
registry.register(MOBILE_BASE_PATTERN, new MobileFileBrowseHandler(context));
httpService.setHandlerResolver(registry);
}
public void runServer() {
new Thread(new Runnable() {
public void run() {
try {
serverSocket = new ServerSocket(Constants.DEFAULT_SERVER_PORT);
serverSocket.setReuseAddress(true);
while (RUNNING) {
try {
final Socket socket = serverSocket.accept();
DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection();
serverConnection.bind(socket, new BasicHttpParams());
httpService.handleRequest(serverConnection, httpContext); //ERROR UCCURS!!!
serverConnection.shutdown();
} catch (IOException e) {
e.printStackTrace();
} catch (HttpException e) {
e.printStackTrace();
}
}
serverSocket.close();
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
RUNNING = false;
}
}).start();
}
MobileFileBrowseHandler.java
public void handle(HttpRequest request, HttpResponse response,
HttpContext context) throws HttpException, IOException {
HttpEntity entity = null;
String uriString = request.getRequestLine().getUri().substring(13);
contentType = URLConnection.guessContentTypeFromName(file.getAbsolutePath());
HttpEntity entity = new FileEntity(file, contentType);
response.setHeader("Content-Type", contentType);
response.setEntity(entity);
}
また、クライアント側で次のコードを使用して、ビデオを見たり音楽を聴いたりします。
public static void IntentPlayer(Context context, Uri uri, int mode){
String type;
switch(mode){
case 1: type = "video/*"; break;
case 2: type = "audio/*"; break;
default: return;
}
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri, type);
context.startActivity(intent);
}
私は何を間違っていますか?どんな助けでも大歓迎です!