我正在尝试将ping结果(isAlive
)添加到下面的流中,以便稍后我可以管道到http响应但我收到以下错误
events.js:85
throw er; // Unhandled 'error' event
我不明白这意味着什么,并感激我得到的任何帮助?
var Readable = require('stream').Readable;
var s = new Readable;
var ping = require('ping');
var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
hosts.forEach(function(host){
ping.sys.probe(host, function(isAlive){
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
//console.log(msg);
s.push(msg)
});
});
//s.push(null) ;
//s.pipe(process.stdout);
答案 0 :(得分:1)
我修改了你的代码:
var Readable = require('stream').Readable;
var s = new Readable();
var ping = require('ping');
s.on('error', function(err){
console.error(err)
})
var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
hosts.forEach(function(host){
ping.sys.probe(host, function(isAlive){
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
//console.log(msg);
s.push(msg);
})
});
您错过了()
var s = new Readable
()
通过向您的阅读器添加error
侦听器,您会看到您正在使用的工具引发以下错误:Error: not implemented
抱歉,我以为我早些时候发过这封邮件。幸运的是,堆栈可以保存未提交的帖子。