Node.Js: how to know, if a socket stream chunk is a partial and needs a next one?

Posted 3 years ago by keevitaja
"use strict";

const net = require('net');

const socket = net.createConnection(6555, '198.178.123.109', ()=> {
    console.log('Connected!');
});

socket.on('data', (chunk)=> {
    console.log(chunk); 
});

The example above receives stream in 2 chunks before starts waiting for the username. How can i determine, that the first chunk is incomplete stream partial and needs the second one to be complete stream data.

This data event is fired twice. Both are partials, but the second one is the last one. The last one completes the first one.

The next chunk is already a new stream.

The goal is to concat the partials to have a complete streams

Please sign in or create an account to participate in this conversation.