我只是試圖連接一個包含域名解析結果的域的數組。Node.js DNS響應延遲
這是我的代碼:
var ipList = [];
for(var j=0; j < addressList.length; j++) {
dns.resolve(addressList[j], function(error, ipRange) {
if(error !== null) {
console.log('The DNS request failed.');
}
console.log('--1--');
console.log(ipRange);
console.log('--2--');
ipList.concat(ipRange);
});
}
console.log(ipList);
我得到的結果是這樣的:
[]
--1--
[ '173.194.35.144',
'173.194.35.145',
'173.194.35.146',
'173.194.35.147',
'173.194.35.148' ]
--2--
它看起來像DNS解析concat()
後響應到達,喜歡它被推遲。 這意味着ipList是一個空數組。
任何人都可以幫助我嗎? 在此先感謝!
由於某種原因仍然不工作::S –
你的'ipList.concat'調用應該是'ipList.push'。我的帖子。 – JohnnyHK
哦,是啊完全錯過了。現在一切正常。感謝您的快速回答! –