2017-11-06 6 views
1

가 발생합니다. 예외는 다음과 같습니다.다트의 HTTP 서버는이 간단한 다트 프로그램을 시작하고 잠시 동안 실행하지만, 일부 상호 작용 이후에 예외를 throw하는 예외

Unhandled exception: 
SocketException: OS Error: Broken pipe, errno = 32, address = ::, port = 443 
#0  _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1108) 
#1  _microtaskLoop (dart:async/schedule_microtask.dart:41) 
#2  _startMicrotaskLoop (dart:async/schedule_microtask.dart:50) 
#3  _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:99) 
#4  _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:152) 

버그입니까?

어떻게 문제를 해결할 수 있습니까?

다른 주제 ... 적절한 암호를 제공하지 않고 https 서버를 시작할 수있는 이유는 무엇입니까? 서버가 암호가 맞는지 확인하길 기대하니?! ...

가 나는 예외

import 'dart:io'; 
import 'package:http_server/http_server.dart'; 

main() async { 


    //files 
    var staticFiles = new VirtualDirectory("file"); 
    staticFiles.allowDirectoryListing = true; 
    staticFiles.directoryHandler = (dir, request) { 
    try{ 
     var indexUri = new Uri.file(dir.path).resolve('index.html'); 
     staticFiles.serveFile(new File(indexUri.toFilePath()), request); 
    } catch(a,b) { 
     print(a); 
     print(b); 
    } 
    }; 


    //http 
    HttpServer 
    .bind(InternetAddress.ANY_IP_V6, 80) 
    .then((server) { 
     try{ 
     server.forEach(staticFiles.serveRequest); 
     } catch(a,b) 
     { 
     print(a); 
     print(b); 
     } 
    } 
); 

    //https 
    SecurityContext context = new SecurityContext(); 
    var chain = Platform.script.resolve('file.pem').toFilePath(); 
    var key = Platform.script.resolve('file.pem').toFilePath(); 
    context.useCertificateChain(chain); 
    context.usePrivateKey(key, password: 'pwd'); 
    HttpServer 
    .bindSecure(InternetAddress.ANY_IP_V6, 443, context) 
    .then((server) { 
     try { 
      server.forEach(staticFiles.serveRequest); 
     } catch(a, b){ 
      print(a); 
      print(b); 
     } 
     } 
); 

을 잡기 해결하려하지만 도움이되지 않았다

답변

3

http_server (그리고 일반적으로 다트의 HTTP 지원) 암호 기반 인증을 지원하지 않습니다.

핵심 지원 위에 이러한 것을 구현할 수 있지만 그게 전부입니다. 정적 파일 솔루션을 찾고 있다면

, 나는 시작하는 것이 훨씬 쉬울 것이다 https://pub.dartlang.org/packages/shelf_static

보고 싶은데.

+0

내 프로그램으로 인해 예외가 발생하는 이유는 무엇입니까? – Michael