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