能够在端口linux234
上对服务器2345.
执行成功的telnet操作,这意味着以下代码应将输出显示为0
但是,代码输出返回异常TypeError: Cannot read property 'write' of undefined at Socket.connect (net.js:901:12) at Promise (internal/util.js:274:30) at new Promise (<anonymous>) at internal/util.js:273:12
const net = require('net');
const util = require('util');
let HOST = 'linux234';
let PORT = 2345;
let ErrCode = 1;
let client = new net.Socket();
let connect = util.promisify(client.connect);
async function performTelnet() {
try {
let data = await connect(PORT, HOST);
ErrCode = 0;
console.log('Client received: ' + data);
if (data.toString().endsWith('exit')) {
client.destroy();
}
}
catch (ex) {
ErrCode = -1;
console.log(ex);
}
}
performTelnet().then(() => {
console.log(ErrCode)
}
)