0
votes

When I send a small message up to 64KB it works correct and returns the number of bytes. When I send a large message, returns zero

Client

TcpClient client = new TcpClient("127.0.0.1",21);
stream = client.GetStream();
byte[] dataToSend= Encoding.UTF8.GetBytes(msg);//large message 1MB or more
stream.Write(outStream, 0, outStream.Length );
stream.Flush();

Server

byte[] array = new byte[1024];
var readBytes = stream.Read(array, 0, array.Length);
1

1 Answers

0
votes

You probably are encountering the end of the stream:

The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.

Read returns 0 only when there is no more data in the stream and no more is expected (such as a closed socket or end of file)