http.serverresponse 객체의 최종 방법이 호출되기 전에 연결이 중단되면 http.serverresponse 객체의 닫기 이벤트가 트리거됩니다.
코드 사본은 다음과 같습니다.
var http = 요구 사항 ( "http");
var server = http.createserver (function (req, res) {
if (req.url! == "/favicon.ico") {
res.on ( "Close", function () {
Console.log ( "연결 인터럽트")
});
settimeout (function () {
res.setheader ( "content-type", "text/html");
res.write ( "<html> <head> <meta charset = 'utf-8' /> < /head>");
res.write ( "Hello");
res.end ();
}, 10000);
}
});
Server.Listen (1337, "LocalHost", function () {
console.log ( "청취 시작"+server.address (). port+"...");
});
위의 코드는 다음과 같습니다.
클라이언트가 요청하면 10 초 후에 클라이언트에게 "hello"를 보내고 동시에 가까운 이벤트를 듣습니다.
서버가 10 초 이내에 닫히는 한, res.end () 메소드가 10 초 이내에 실행되지 않기 때문에 서버는 "연결 중단"이됩니다.