Created
September 25, 2015 12:58
-
-
Save arthurschreiber/f9e11e34adc6e0140867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var net = require('net'); | |
var http = require("http"); | |
var count = 0; | |
var server = http.createServer(function(req, res) { | |
var id = res.id = count++; | |
var connection = res.connection; | |
console.log("----> Closing", id, "in", (2 - id) * 10, "seconds"); | |
res.on('prefinish', function() { | |
console.log("Event: prefinish", id); | |
}); | |
res.on('finish', function() { | |
console.log("Event: finish", id); | |
}); | |
res.on('close', function() { | |
console.log("Event: closed", id); | |
}); | |
res.on('error', function(err) { | |
console.log("Event: error", err); | |
}); | |
res.on('end', function() { | |
console.log("Event: end", err); | |
}); | |
setTimeout(function() { | |
console.log("----> Closing", id, "now"); | |
res.end('hello'); | |
}, (2 - id) * 10); | |
if (id === 1) | |
server.close(); | |
}); | |
server.listen(8080, function() { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('Example app (' + process.pid + ') listening at http://%s:%s', host, port); | |
var s = net.connect(port); | |
var req = 'GET / HTTP/1.1\r\nConnection: close\r\n\r\n'; | |
var big = req + req; | |
s.end(big); | |
s.resume(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment