Actually I have a problem with javascript code executed using node.js I need to send HTTP requests in a loop to a remote server (I installed www.google.ca in the code). Here is my code:
var http = require('http');
var options = {
hostname: 'www.google.ca',
port: 80,
path: '/',
method: 'GET'
};
function sendRequest(options){
console.log('hello');
var start = new Date();
var req = http.request(options,function(res) {
console.log('Request took:', new Date() - start, 'ms');
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();
};
for(var i=0;i<10;i++){
sendRequest(options);
}
The problem is that no matter how many times I look at my cycle, I get an answer for only the first 5 of them. For the rest of the requests, the sendRequest () function is called, but I do not receive any responses or error messages. And then the program ends. However, it works fine when I set localhost as the host. Will anyone have a solution to this problem? Thank you in advance!
source
share