I am transferring a file over a NetworkStream and it seems that when the file goes over about 5-10k, the file starts to miss out on data and/or have huge whitespace gaps.
Here is what I have:
private string ReadandSaveFileFromServer(TcpClient clientATF, NetworkStream currentStream, string locationToSave)
{
int fileSize = 0;
string fileName = "";
int bytesRead = 0;
fileName = ReadStringFromServer(clientATF, currentStream);
fileSize = ReadIntFromServer(clientATF, currentStream);
FileStream fs = new FileStream(locationToSave + "\\" + fileName, FileMode.Create);
byte[] fileSent = new byte[fileSize];
while (currentStream.DataAvailable)
{
if (clientATF.Connected)
{
bytesRead = currentStream.Read(fileSent, 0, fileSent.Length);
fs.Write(fileSent, 0, fileSent.Length);
}
else
{
break;
}
}
fs.Flush();
fs.Close();
return fileName;
}