Skip to content

Instantly share code, notes, and snippets.

@ry
Created January 27, 2010 17:20
Show Gist options
  • Save ry/288020 to your computer and use it in GitHub Desktop.
Save ry/288020 to your computer and use it in GitHub Desktop.
process.mixin(require("./common"));
var tcp = require("tcp"),
sys = require("sys"),
http = require("http");
var PORT = 2143;
var errorCount = 0;
var eofCount = 0;
var server = tcp.createServer(function(socket) {
socket.addListener("connect", function(data) {
setTimeout(function(){ socket.close(); }, 1000);
});
});
server.listen(PORT);
var client = http.createClient(PORT);
client.addListener("error", function() {
sys.puts("ERROR!");
errorCount++;
});
client.addListener("eof", function() {
sys.puts("EOF!");
eofCount++;
});
var request = client.request("GET", "/", {"host": "localhost"});
request.finish(function(response) {
sys.puts("STATUS: " + response.statusCode);
});
process.addListener('exit', function () {
assert.equal(0, errorCount);
assert.equal(1, eofCount);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment