2
HttpService
을 사용하여 일부 파일을 공유하기 위해 Android 기기 및 브라우저에 응답을 보냅니다. 이 서비스는 안드로이드 장치에서 작동합니다. 모든 것이 잘 작동하여 비디오 파일을 제외시킵니다. 온라인 음악 감상은 완벽하게 작동합니다. 나는 온라인 비디오를 시청하려고 할 때하지만 내 WebService
은 아래 볼 수있는 오류와 함께 실패합니다 :HttpService - 온라인 동영상을 재생할 수 없습니다.
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);
}
그리고 clie에서 다음 코드를 사용합니다. nt 쪽에서 동영상을 보거나 음악을 들으세요 :
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);
}
내가 뭘 잘못하고 있니? 어떤 도움을 주시면 감사하겠습니다!
이 문제를 해결할 수 있었습니까? – adi