javascript - strings get concatenated on other end in TLS socket connection in node -
i tailing file using tail-always , transferring data server using tls socket in node. here code transfer lines server
var client = tls.connect(port,serveraddress, options, function() { tail.on('line', function(data) { console.log(data.tostring('utf-8')) client.write(data.tostring('utf-8')); }); tail.on('error', function(data) { console.log("error:", data); }); tail.watch(); });
on side server listens port , grabs text. code :
var server = tls.createserver(options, function(tslsender) { tslsender.on('data', function(data) { console.log(data.tostring('utf-8')); }); tslsender.on('close', function() { console.log('closed connection'); }); });
the program works when single line added @ time file , when multiple line added file lines gets concatenated on server side.i have confirmed not getting concatenated before client.write function.
how can solve problem ?
a standard stream
bunch of bytes. writing 1 line @ time @ 1 end of stream has no effect on how data received @ other end. if want server process data receiving 1 line @ time, need on server using split
.
var split = require('split'); var server = tls.createserver(options, function(tslsender) { let linestream = tslsender.pipe(split()); linestream.on('data', function(data) { console.log(data.tostring('utf-8')); }); tslsender.on('close', function() { console.log('closed connection'); }); });
Comments
Post a Comment