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