I'm a beginner learning sockets for a few days now
private void SendFile(Socket client, string user, string folder1, string folder2, string zipFile)
{
byte[] zipBytes = File.ReadAllBytes(zipFile); //file
string fileInfoStr = user + ","
+ folder1 + ","
+ folder2 + ","
+ Path.GetFileName(zipFile) + ","
+ zipBytes.Length;
byte[] fileInfo = Encoding.UTF8.GetBytes(fileInfoStr);
byte[] fileInfoLen = BitConverter.GetBytes(fileInfo.Length);
var clientData = new byte[4 + fileInfo.Length + zipBytes.Length];
fileInfoLen.CopyTo(clientData, 0);
fileInfo.CopyTo(clientData, 4);
zipBytes.CopyTo(clientData, 4 + fileInfo.Length);
// Begin sending the data to the remote device.
client.BeginSend(clientData, 0, clientData.Length, 0,
new AsyncCallback(SendCallback), client);
Receive(client);
}
The problem is for example I try to send a large zip file(300mb), the memory usage shoots up to 600mb+. I'm stuck on how can I decrease the memory usage. Thanks.