字符串在节点中的 TLS 套接字连接中的另一端连接

strings get concatenated on other end in TLS socket connection in node

我正在使用 tail-always 拖尾文件 并使用节点中的 TLS 套接字将数据传输到另一台服务器。这是将线路传输到另一台服务器的代码

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();
});

在另一端服务器侦听端口并抓取文本。代码是:

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');
    });
});

当一次向文件中添加一行时,该程序运行完美,但是当向文件中添加多行时,这些行在服务器上被连接起来 side.I 已确认它们没有被连接起来在 client.write 函数之前。
我该如何解决这个问题?

一个标准的stream就是一堆字节。在流的一端一次写入一行不会影响另一端接收数据的方式。如果您希望您的服务器一次处理它接收到的一行数据,您需要在服务器上使用类似 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');
    });
});