【发布时间】:2020-02-05 23:17:32
【问题描述】:
我在nodejs中写了以下tcp client。
const net = require('net');
const HOST = 'linux345';
const PORT = 2345;
let ErrCode = 1;
const client = new net.Socket();
client.connect(PORT, HOST, function() {
ErrCode = 0;
});
client.on('data', function(data) {
console.log('Client received: ' + data);
if (data.toString().endsWith('exit')) {
client.destroy();
}
});
client.on('close', function() {
});
client.on('error', function(err) {
ErrCode = err.code;
console.log(ErrCode);
});
console.log(ErrCode);
请建议我如何使用 async/await 编写相同的逻辑
我查看了以下帖子,但没有帮助。 node 7.6 async await issues with returning data
【问题讨论】:
标签: javascript node.js angular promise async-await