interacts with a telent server, server communication code is gb2312
currently, the content requested from the server can be decoded with iconv, and the gb2312 sent by the server shows normal after decoding
telnetInput.pipe(through2((chunk, enc, callback) => {
chunk = iconv.decode(chunk, "gbk");
chunk = chunk.replace(/((?:[\n\r]|^)<.*?>)\n\r?/g, "$1 ");
if (chunk) {
callback(null, chunk);
} else {
callback(null);
}
})).pipe(process.stdout);
but when sent to the server, the string type supported by nodejs does not have gbk class encoding
when typing, the encoding supported by readline,readline is consistent with that of nodejs, so if a friend replied before, use the ready-made module gbk to report an error that is not supported by coding.
this.telnetOutput.write(rawStr + "\n");
although the nodejs writable stream wirte supports the specified encoding, it also does not contain Chinese. The utf8 code is still received when sending Chinese to the server.
since the request for downlink data can be gbk encoding, how to send the original gbk encoding to the server?