Skip to content

Instantly share code, notes, and snippets.

@sspencer
Created April 13, 2011 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sspencer/918514 to your computer and use it in GitHub Desktop.
Save sspencer/918514 to your computer and use it in GitHub Desktop.
Working Multi Proxy
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