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连接连接到设备,一切正常。.我在'ready','close'等上获取控制台日志,但是在打开时无法获取控制台日志发生“错误”。

我可以在32位win7上捕获'error'事件,但不能在MacOSx(10.9.5)或Linux(Ubuntu 12)上捕获。当我强行终止与设备的连接时(例如,从系统中插入局域网电缆),将触发on“错误”事件。

这是对Mac/Linux ssh2模块的限制吗?还是我在捕获错误的方式上做错了什么?

任何指针将非常有帮助。

节点js版本v0.10.29
ssh2版本v0.4.8

最佳答案

在github中提出了这个问题
https://github.com/mscdex/ssh2/issues/364

解决方案是使用keepaliveInterval,它的默认值为0。因此,为了使我的应用程序保持最佳值,它可以正常工作。

关于javascript - Node js :Not able to catch 'error' in ssh2 connection on MacOSx/Linux,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34046056/

10-16 20:46