Sorry, this is a xpost iwth Stackoverflow, but I still have not found an answet to this (apparently) simple question:
I'm trying to set a timeout on an HTTP client that uses http.request with no luck. So far what I did is this:
var options = { ... }
var req = http.request(options, function(res) {
// Usual stuff: on(data), on(end), chunks, etc...
}
/* This does not work TOO MUCH... sometimes the socket is not ready (undefined) expecially on rapid sequences of requests */
req.socket.setTimeout(myTimeout);
req.socket.on('timeout', function() {
req.abort();
});
req.write('something');
req.end();
Btw, this tecnique works fine:
http://stackoverflow.com/questions/6129240/how-to-set-timeout-for-http-createclient-in-node-jsIf I use the socket timeout, and I issue two
requests one after another (without waiting the first to finish), the
second request has the socket undefined (at least at the moment I try to
set the timeout).. maybe there should be something like on("ready") on
the socket...Any hints?