title: c# sockets missing data
body: <p>I have the following code to read messages sent from a server to the client:</p>
  
  <pre><code>while (true) {
      byte[] readBuffer = new byte[327680];
      StringBuilder message = new StringBuilder(327680);
      while (true) {
          do {
              int bytes = ServerStream.Read(readBuffer, 0, readBuffer.Length);
              message.AppendFormat("{0}", Encoding.ASCII.GetString(readBuffer, 0, bytes));
          }
          while (ServerStream.DataAvailable);
  
          if (message.Length &gt; 0) {
              foreach (string msg in message.ToString().Split(MESSAGE_END)) {
                  if (msg != "") ProcessServerMessage(msg);
              }
              message.Clear();
              readBuffer = new byte[327680];
          }
      }
  }    
  </code></pre>
  
  <p>Unfortunately... Every now and then the variable 'message' appears to chop off, for no reason I can understand. I've made the read buffer huge, to see if that was the issue, but it doesn't help. It seems to happen when the server sends lots of data at once, but nowhere near 327680 bytes... </p>
  
  <p>Also, when checking the server logs, it appears to be sending the data completely, un-chopped. It's like half the info is 'lost' on the internet somewhere... But this is TCP, so that shouldn't happen, right?</p>
  
  <p>Thanks in advance</p>