Reputation: 33
Is there a means by which I can specify the outgoing IP address for a client connection when using Node.js?
Upvotes: 3
Views: 1160
Reputation: 393
It is available since 2013.01.11 Version 0.9.6 (Unstable) release, with localAddress
option.
var options = {
hostname: 'www.google.fr',
localAddress: '192.168.0.2',
};
var req = http.get(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
Upvotes: 0
Reputation: 25466
it seems at the moment the only solution is to use _createServerHandle
function
var s = new net.Socket({ handle:
net._createServerHandle(localAddress) });
s.connect(port, host, cb);
see this thread on mailing list.
Upvotes: 2