I want to know what determines the size of data when a tcp socket emitted an 'data' event as following, thx!
var client = new Socket(options);
client.on('data', chunk => {}); // what determines the size of chunk?
When a IP packet with aTCP segment arrives, the data contained will be pushed into the internal buffer of net.Socket (which is a duplex stream ) with stream.push(chunk).
Provided that net.Socket is in flowing mode, the data added with stream.push(chunk) will be delivered with a 'data' event. As a result, the size of the chunk corresponds to the data of the TCP segment which arrived.
However, if the stream is paused and then resumed, the chunk released afterwards will not correspond to the data contained to a single TCP segment.
The stream internal buffer can hold data up to highWaterMark threshold.
See details on buffering and highWaterMark here:
https://nodejs.org/api/stream.html#stream_buffering
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With