Created
April 13, 2011 21:54
-
-
Save sspencer/918514 to your computer and use it in GitHub Desktop.
Working Multi Proxy
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
var http = require('http'); | |
// Working multiproxy - can call setTimeout multiple times. | |
function sendRequest(hostname) { | |
var client = http.createClient(80, hostname); | |
client.setTimeout(5000); | |
var req = client.request('GET', '/'); | |
client.addListener('timeout', function (error) { | |
console.log("request to " + hostname + " timed out."); | |
}); | |
req.addListener('response', function (res) { | |
var body = []; | |
res.addListener('data', function (chunk) { | |
body.push(chunk); | |
}); | |
res.addListener('end', function () { | |
console.log("Received " + body.join("").length + " bytes from " + hostname); | |
}); | |
}); | |
req.end(); | |
}; | |
// Works with 2 different hosts | |
//var requests = ["www.yahoo.com", "www.google.com"]; | |
// And works with same host | |
var requests = ["www.google.com", "www.google.com"]; | |
requests.forEach(function(r) { | |
sendRequest(r); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment