title: TcpClient VS Socket in large file transfer
body: <p>I have to trnasfer large file, at this moment I use TcpClient and NetworkStream class to do that, but it isn't enought. When I use NetworkStream.Write and Read it lose bytes I don't know how can I ensure that TCP will stop reading when all bytes will be ok.</p>
  
  <p>Then I found Socket Class, and now my question, "Socket will be perfectly sure about all bytes before it end read?"</p>
  
  <p>How I recive file:</p>
  
  <pre><code>            byte[] VideoFrom = new byte[FizeSizeSendedBefore];
              byte[] PartData = new byte[clientSocket.ReceiveBufferSize];
              int PartNumbers = (VideoSize / clientSocket.ReceiveBufferSize) + 1;
              int lastPackageSize = VideoSize - ((PartNumbers - 1) * clientSocket.ReceiveBufferSize);
  
              int i;
              int bytesToRead = 0;
              int ActualSize = 0;
              for (i = 0; i &lt; PartNumbers; i++)
              {
                  if (i &lt; PartNumbers - 1)
                  {
                      bytesToRead = clientSocket.ReceiveBufferSize;
                  }
                  else
                  {
  
                      bytesToRead = lastPackageSize;
                  }
                  ActualSize += bytesToRead;
  
  
                  PartData = new byte[bytesToRead];
  
                  System.Threading.Thread.Sleep(2);
  
                  networkStream.Read(PartData, 0, bytesToRead);
  
                  Buffer.BlockCopy(PartData, 0, VideoFrom, i * clientSocket.ReceiveBufferSize, bytesToRead);
              }
  
  
  
              if (!Directory.Exists("./temp/anwsers/" + AnwserXML.Attribute("number").Value)) { Directory.CreateDirectory("./temp/anwsers/" + AnwserXML.Attribute("number").Value); }
              File.WriteAllBytes("./temp/anwsers/" + AnwserXML.Attribute("number").Value + "/" + AnwserXML.Attribute("client").Value + ".mov", VideoFrom);
  
  
          }
  </code></pre>
  
  <p>How I send file</p>
  
  <pre><code>int PartNumber = (FizeSizeSendedBefore/ clientSocket.ReceiveBufferSize) + 1;
              int lastPackageSize = FileSize - ((PartNumber - 1) * clientSocket.ReceiveBufferSize);
              int i;
              for (i = 0; i &lt; PartNumber; i++)
              {
                  if (i &lt; PartNumber - 1)
                  {
                      while (!serverStream.CanRead) { }
                      serverStream.Write(outStream, i * clientSocket.ReceiveBufferSize, clientSocket.ReceiveBufferSize);
                  }
                  else
                  {
                      while (!serverStream.CanRead) { }
                      serverStream.Write(outStream, i * clientSocket.ReceiveBufferSize, lastPackageSize);
                  }
  
              }
  </code></pre>