I've got a simple Node.JS server:
//Module dependencies
var net = require('net')
//Create server
var server = net.createServer(function (conn) {
// handle connection
conn.setEncoding('utf8');
conn.write(
'Hi, please enter something: '
);
conn.on('data', function (data) {
console.log(data);
});
});
//Listen
server.listen(3000, function () {
console.log('\033[96m server listens at *:3000\033[39m');
});
It is supposed to echo a client's input in server's console window. But when I connect to the server using telnet client, it does so by outputting character by character, while I would rather it output line by line on pressing Enter.
I know I cann collect all the input in the conn.on
method, but can it be done on a lower level?
That's because telnet flushes the TCP buffer after every character unless you use linemode.