"use strict";
const net = require('net');
const socket = net.createConnection(6555, '198.178.123.109', ()=> {
process.stdin.pipe(socket);
});
let line = '';
socket.on('data', chunk => {
let str = chunk.toString();
for (let i = 0, len = str.length; i < len; i++) {
let chr = str[i];
line += chr;
process.stdout.write(chr);
if (/[\n\r]$/.test(chr)) {
process.stdout.write(line);
line = '';
}
}
});
However, if input is expected, the line might *not* terminate, it must just stop on "login" or might stop on whatever.
so, how do you "get" that very last line?
Here's my horrible kludge:
http://stackoverflow.com/a/18521863/2628...
However, that's just horrible, horrible. Surely this is a solved problem. How do MUD clients get all the lines, even ones which don't terminate correctly?