1
this.connection = new Connection(); //ssh2 connection
async.waterfall([function(callback) {
// some initialization code to connect
}
}], function(err, opts) {
if (err) {
callback({
message: 'Error during connecting to the device...',
detail: err
}, false);
} else {
console.log('Connecting to ... ' + JSON.stringify(self.info));
self.connection.on('ready', function() {
console.info('Connected... opening a shell...');
callback(null, true);
}).on('error', function(err) {
console.error('Error during connecting to the device: ' + err);
callback({
message: 'Error during connecting to the device...',
detail: err
}, false);
}).on('end', function() {
console.info("Connection ended...");
}).on('close', function(hadError) {
console.info("Connection closed..." + (hadError ? " with error" : ""));
}).connect(opts);
}
});
参考上面的代码SSH2连接,我使用的是SSH2连接连接到设备,一切正常fine..I我得到控制台日志对'就绪','关闭'等等,但是当发生'错误'时无法获得控制台日志。节点JS:没能赶上“错误”在MacOSX上/ Linux的
我可以捕获win7 32位上的'错误'事件,但不能在MacOSx(10.9.5)或Linux(Ubuntu 12)上捕获。当我强行结束与设备的连接时(例如,从我的系统中拔出LAN电缆),触发'错误'事件。
这是Mac/Linux w.r.t ssh2模块的一些限制,还是我在捕捉错误的方式上做错了什么。
任何指针都会很有帮助。
节点js版v0.10.29 SSH2版本v0.4.8