Node.js: how to hide a socket?

I am trying to clear the socket before sending the following piece of data:

var net = require('net');

net.createServer(function(socket) {
    socket.on('data', function(data) {
        console.log(data.toString());
    });
}).listen(54358, '127.0.0.1');

var socket = net.createConnection(54358, '127.0.0.1');

socket.setNoDelay(true);
socket.write('mentos');
socket.write('cola');

This, however, does not work, despite the setting setNoDelay, for example. prints "menthol" instead of "mentos \ ncola". How to fix it?

+5
source share
2 answers

Looking back at the WriteableStreamapi and the corresponding example , it seems to you that you should set your own breaks or delimiters yourself.

exports.puts = function (d) {
  process.stdout.write(d + '\n');
};

, / , #write , , , , .

, .

: Nodejs streaming, , : , .

+5

, , , .

, node .

0
source

All Articles