2010-12-05 07:20:34 +08:00
|
|
|
var common = require('../common');
|
2010-12-06 06:33:52 +08:00
|
|
|
var assert = require('assert');
|
2010-01-28 01:34:45 +08:00
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
var net = require('net'),
|
|
|
|
util = require('util'),
|
|
|
|
http = require('http');
|
2010-01-28 01:34:45 +08:00
|
|
|
|
|
|
|
var errorCount = 0;
|
|
|
|
var eofCount = 0;
|
|
|
|
|
2010-08-11 08:37:30 +08:00
|
|
|
var server = net.createServer(function(socket) {
|
2010-04-09 01:44:22 +08:00
|
|
|
socket.end();
|
2010-01-28 01:34:45 +08:00
|
|
|
});
|
2010-12-03 09:03:18 +08:00
|
|
|
server.on('listening', function() {
|
2010-08-11 08:37:30 +08:00
|
|
|
var client = http.createClient(common.PORT);
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
client.addListener('error', function(err) {
|
|
|
|
console.log('ERROR! ' + (err.stack || err));
|
2010-08-11 08:37:30 +08:00
|
|
|
errorCount++;
|
|
|
|
});
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
client.addListener('end', function() {
|
|
|
|
console.log('EOF!');
|
2010-08-11 08:37:30 +08:00
|
|
|
eofCount++;
|
|
|
|
});
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
var request = client.request('GET', '/', {'host': 'localhost'});
|
2010-08-11 08:37:30 +08:00
|
|
|
request.end();
|
|
|
|
request.addListener('response', function(response) {
|
2010-12-03 09:03:18 +08:00
|
|
|
console.log('STATUS: ' + response.statusCode);
|
2010-08-11 08:37:30 +08:00
|
|
|
});
|
2010-01-28 01:34:45 +08:00
|
|
|
});
|
2010-08-11 08:37:30 +08:00
|
|
|
server.listen(common.PORT);
|
2010-01-28 01:34:45 +08:00
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
setTimeout(function() {
|
2010-01-28 01:34:45 +08:00
|
|
|
server.close();
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
process.addListener('exit', function() {
|
2010-01-28 01:34:45 +08:00
|
|
|
assert.equal(0, errorCount);
|
|
|
|
assert.equal(1, eofCount);
|
|
|
|
});
|