I have win socket apps which are described here. So far, I was using ReadAllBytes
method and read everything from my big file into memory. I made a new method which will read my file in chunks which will help my memory. Here is the method:
public static void ChunksToSend(string path)
{
int chunkSize = 1024;
byte[] chunk = new byte[chunkSize];
using (FileStream fileReader = new FileStream(path, FileMode.Open, FileAccess.Read))
{
BinaryReader binaryReader = new BinaryReader(fileReader);
int bytesToRead = (int)fileReader.Length;
do
{
chunk = binaryReader.ReadBytes(chunkSize);
bytesToRead -= chunkSize;
} while (bytesToRead > 0);
binaryReader.Close();
}
}
Now, I need to connect my new method with this line from the link at Client side:
int bytesSent = sender.Send(result);
It looks easy, but I have a problem with TCP header which I need to send to in order to get file size and extension code. Lines at client side are:
//join arrays, file size info, TCP header
...
//file extension info, TCP Header
So, I need to join everything and to send it in iteration like I was doing it before chunks. The question might look easy, but I would not post it if I could do it. Thanks.
UPDATE:
For the first 4 bytes where I am sending file size info, I was using information from ReadAllBytes
, but now I can use:
long length = new System.IO.FileInfo(path).Length;