Javascript 无法使用';telnet客户端';模块
我可以使用命令提示符执行telnet,但是通过NodeJs得到一个错误Javascript 无法使用';telnet客户端';模块,javascript,node.js,async-await,node-modules,Javascript,Node.js,Async Await,Node Modules,我可以使用命令提示符执行telnet,但是通过NodeJs得到一个错误 'use strict' const Telnet = require('telnet-client') async function run() { let connection = new Telnet() let params = { host: 'linuxserver123', port: 1603, shellPrompt: '/ # ',
'use strict'
const Telnet = require('telnet-client')
async function run() {
let connection = new Telnet()
let params = {
host: 'linuxserver123',
port: 1603,
shellPrompt: '/ # ',
timeout: 4500
}
try {
await connection.connect(params)
} catch(error) {
}
let res = await connection.exec('uptime')
console.log('async result:', res)
}
run()
我得到以下错误:
此错误来自connect()
你能用另一个端口吗?高于1024。1024以下的端口是系统保留的,这可能会导致问题。另外,在
等待连接周围放置一个try/catch块。exec
和catch/log该错误,这样您就可以获得比未处理PromiserRejection更多的信息…
会让您在更高的端口port:1603
@Christopherid上获得相同的错误。该限制只适用于服务器,而不是客户端。@Barmar说得好!不过,这里没有太多的信息可供参考,所以我只是在想方设法。获取实际的错误日志而不是PromisejectionWarning会很有帮助。@ChristopherId您真的希望得到比错误:套接字不可写
更详细的信息吗?
errer connecting Error: Socket ends
at Socket.socket.on (project/lib/index.js:110:18)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1059:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
(node:12139) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: socket not writable
(node:12139) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.