Whatever you set it according to your code i
is the actual bytes read from socket, so a byteSize
doesn't help you if i
is pretty much smaller than byteSize
.
Inside your while
you should check if i
is smaller that byteSize
and if so, copy the first i
bytes of your byte
(byte array) to a safe place i.e a memory stream or a file stream and continue to read socket to get to the end of network stream (where i = 0). 1024, 2048 and 4096 seems good depending on your network speed, available memory and threads which are using such a buffer. For example using 100 threads with 1024 buffer size cost you 100 KB of RAM which is nothing at today's hardware scale.
Personally most of the times use a smart buffer, I mean at run time I check read amount against buffer size and correct it to get a better result (albeit if it worth according to the project).