1
我有一個客戶端服務器應用程序,通過wcf在傳輸模式流進行通信。 當客戶端試圖下載文件的時候,它的工作正常,但是當客戶端嘗試把整個文件放在2個PE中時,下載的文件被損壞並且無法打開。流文件部分 - 不工作
客戶端代碼:
public void DownloadPart(Part Part) //Part: Part.From,Part.To -> possitions in the stream from where to begin and when to end reading
{
int ReadUntilNow = 0;
int ReadNow = 0;
byte[] Array= new byte[15000];
long NeedToDownload = Part.To - Part.From;
using (FileStream MyFile = new FileStream(Path_To_Save_The_File, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
MyFile.Position = Part.From;
while (ReadUntilNow < NeedToDownload)
{
ReadNow = this.SeederInterface.GetBytes(TorrentID, Part.From + ReadUntilNow, ref Array);
ReadUntilNow += ReadNow;
MyFile.Write(Array, 0, ReadNow);
}
}
}
服務器代碼:
public int GetBytes(int TorrentID, int Position, ref byte[] Array)
{
FileStream File = new FileStream(FilePatch, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
File.Position = Position;
return File.Read(Array, 0, Array.Length);
}
我真的絕望,不知道是什麼問題。
哇,這是我的錯誤...我不能相信它。非常感謝您的參與!我仍然無法相信我沒有看到它!謝謝你! –