Advertisement
csaki

Miért küldi háromszor?

Sep 21st, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.73 KB | None | 0 0
  1. SZERVEROLDAL:
  2.  case FtpPacket.FileDownloadPacket:
  3.                     Log("File download packet");
  4.                     Log("Everything sent: " + _isEverythingSent.ToString().ToUpper());
  5.                     try
  6.                     {
  7.                         if (_isEverythingSent)
  8.                         {
  9.                             Log("Everything is sent!");
  10.                             Send(Values.Success);
  11.                             return true;
  12.                         }
  13.                         if (!_isFilenameSet)
  14.                         {
  15.                             Log("Send: no filename");
  16.                             Send(Values.NoFilename);
  17.                             return true;
  18.                         }
  19.                         Log("Filebuffer length: " + _fileBuffer.Length);
  20.                         if (_fileBuffer.Length > CHUNK_SIZE) // file is smaller than CHUNK_SIZE, can be sent in one packet
  21.                         {
  22.                             Log("Filesize is bigger than 1024");
  23.                             Log("| current chunk index: " + _currentChunkIndex);
  24.                             if (_fileBuffer.Length - _currentChunkIndex > CHUNK_SIZE)
  25.                             {
  26.                                 Log("The remaining data: " + (_fileBuffer.Length - _currentChunkIndex));
  27.                                 var tmp = GetSubArray(_fileBuffer, _currentChunkIndex, _fileBuffer.Length - _currentChunkIndex);
  28.                                 Send(tmp);
  29.                                 Console.WriteLine(tmp.GetString());
  30.                                 _currentChunkIndex += CHUNK_SIZE;
  31.                             }
  32.                             else
  33.                             {
  34.                                 Log("Filesize is less then 1024");
  35.                                 var tmp = GetSubArray(_fileBuffer, _currentChunkIndex, _fileBuffer.Length - _currentChunkIndex);
  36.                                 Send(tmp);
  37.                                 Console.WriteLine(tmp.GetString());
  38.                                 _isEverythingSent = true;
  39.                             }
  40.                         }
  41.                         else
  42.                         {
  43.                             Log("Send: filebuffer - " + _fileBuffer.GetString());
  44.                             Send(_fileBuffer);
  45.                             _isEverythingSent = true;
  46.                         }
  47.                     }
  48.                     catch (Exception e)
  49.                     {
  50.                         Log(e.Message + "\n" + e);
  51.                         Send(Values.Denied);
  52.  
  53.                         ResetState();
  54.                     }
  55.  
  56.                     return true;
  57.  
  58.  
  59.  
  60. KLIENSOLDAL:
  61.  
  62. // Start downloading
  63.             const int CHUNK_SIZE = 1024;
  64.             List<byte> fileContent = new List<byte>();
  65.             List<string> testList = new List<string>();
  66.             bool succeeded = false;
  67.             bytes = new byte[CHUNK_SIZE];
  68.             while (true) // FileDownloadPacket
  69.             {
  70.                 Send(Values.Download);
  71.                 Send(Values.Endvalue, true);
  72.                 Recieve(bytes);
  73.                 //Console.WriteLine(bytes.GetString());
  74.                 if (bytes.MembersEquals(Values.Success, 2))
  75.                 {
  76.                     succeeded = true;
  77.                     break;
  78.                 }
  79.                 else if (bytes.MembersEquals(Values.Denied, 2) || bytes.MembersEquals(Values.NoFilename, 2))
  80.                 {
  81.                     break;
  82.                 }
  83.                 testList.Add(bytes.GetString());
  84.                 fileContent.AddRange(bytes);
  85.                 bytes = new byte[CHUNK_SIZE];
  86.                
  87.             }
  88.             return succeeded ? fileContent.ToArray() : null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement