2010-03-09 07:06:29 +08:00
|
|
|
require("../common");
|
2010-01-28 01:34:45 +08:00
|
|
|
|
|
|
|
var tcp = require("tcp"),
|
|
|
|
sys = require("sys"),
|
|
|
|
http = require("http");
|
|
|
|
|
|
|
|
var errorCount = 0;
|
|
|
|
var eofCount = 0;
|
|
|
|
|
|
|
|
var server = tcp.createServer(function(socket) {
|
2010-04-09 01:44:22 +08:00
|
|
|
socket.end();
|
2010-01-28 01:34:45 +08:00
|
|
|
});
|
|
|
|
server.listen(PORT);
|
|
|
|
|
|
|
|
var client = http.createClient(PORT);
|
|
|
|
|
|
|
|
client.addListener("error", function() {
|
|
|
|
sys.puts("ERROR!");
|
|
|
|
errorCount++;
|
|
|
|
});
|
|
|
|
|
2010-02-12 16:25:15 +08:00
|
|
|
client.addListener("end", function() {
|
2010-01-28 01:34:45 +08:00
|
|
|
sys.puts("EOF!");
|
|
|
|
eofCount++;
|
|
|
|
});
|
|
|
|
|
|
|
|
var request = client.request("GET", "/", {"host": "localhost"});
|
2010-02-18 03:10:10 +08:00
|
|
|
request.addListener('response', function(response) {
|
2010-01-28 01:34:45 +08:00
|
|
|
sys.puts("STATUS: " + response.statusCode);
|
|
|
|
});
|
2010-04-09 01:44:22 +08:00
|
|
|
request.end();
|
2010-01-28 01:34:45 +08:00
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
server.close();
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
|
|
|
|
process.addListener('exit', function () {
|
|
|
|
assert.equal(0, errorCount);
|
|
|
|
assert.equal(1, eofCount);
|
|
|
|
});
|