我做了一個服務器和客戶端(作爲培訓)。他們都溝通完美。當Iam從我的客戶端上傳文件到我的服務器時,出現唯一的問題。當服務器正在下載我的服務器時 - RAM大約上升860MB( - >下載299MByte文件)。我注意到,每次客戶端上傳我的RAM都不會回到正常值。相反,它被添加到我的服務器當前的RAM值(2個客戶端上傳完畢 - >服務器RAM越過1300MB)下載文件後RAM不增加到正常值
這是從我的服務器我的代碼在那裏reciving文件
private void DownloadFileFromClient(string path, string nameAndExtension, TcpClient client)
{
string currFileName = "Download";
string savingPath = path;
if (File.Exists(savingPath)) //Wenn der Pfad einen Namen für die Datei enthält
{
FileInfo fi = new FileInfo(savingPath);
currFileName = fi.Name;
}
else if (Directory.Exists(savingPath)) //Wenn der Pfad zu einem Ordner führt
{
int counter = 0; //zählt die doppelten Datein nachoben
foreach (string file in Directory.GetFiles(savingPath))
{
FileInfo fi = new FileInfo(file);
string[] name = fi.Name.ToString().Split('.');
if (name[0].ToUpperInvariant() == currFileName.ToUpperInvariant()) //Wenn schon eine Datei mit dem selben Namen vorhanden ist
{
counter++;
currFileName = "download" + counter.ToString();
}
}
savingPath = savingPath + "\\" + currFileName + "." + nameAndExtension;
}
using (NetworkStream stream = client.GetStream())
{
BinaryFormatter bf = new BinaryFormatter();
object op;
op = bf.Deserialize(stream); // Deserialize the Object from Stream
BinaryReader br = new BinaryReader(stream);
byte[] buffer = br.ReadBytes(MaxDownloadBytes); //Maximale Dateiengröße in Bytes 10MB = 10485760Bytes | 50MB = 52428800Bytes | 100MB = 104857600Bytes | 500MB = 524288000Bytes
br.Dispose();
br.Close();
using (FileStream filestream = new FileStream(savingPath, FileMode.CreateNew, FileAccess.Write))
{
filestream.Write(buffer, 0, buffer.Length);
}
}
LogMessage("Succefully downloaded file from Client", client.GetHashCode().ToString(), "Manuel", "test", client);
}
我嘗試了全部處理,但它並沒有幫助很多。謝謝你的回答!
使用探查器並快樂地檢查你的堆。使用這樣的工具,您可以非常快速地識別泄漏。 –
是一個需求的快樂部分? – Jonesopolis