title: C# .Net Sockets Buffer Understanding
body: <p>I'm trying to understand the use of a buffer in the socket scheme of things. Here is what I understand, and if someone could tell me if I'm correct or give feedback to where I might be misunderstanding that would be great.</p>
  
  <p>Using the Asynchronous Sockets detailed on MSDN <a href="http://msdn.microsoft.com/en-us/library/bew39x2a.aspx" rel="nofollow">example</a> (all below is with reference to that example)</p>
  
  <p>Below describes a state object of which I understand the point of:</p>
  
  <pre><code>// State object for reading client data asynchronously
  public class StateObject
  {
      // Client  socket.
      public Socket workSocket = null;
      // Size of receive buffer.
      public const int BufferSize = 1024;
      // Receive buffer.
      public byte[] buffer = new byte[BufferSize];
      // Received data string.
      public StringBuilder sb = new StringBuilder();
  }
  </code></pre>
  
  <p>Now it says the buffer is 1024 bytes. When you recieve data, you are only asking for 1024 bytes at a time? And in the async method ReceiveCallback, it only ask for 1024 and then says this may not be all of the data, so now retrieve the next 1024.</p>
  
  <p>So basically, the input stream sent to the socket is read in 1024 byte chunks and you keep reading till you've hit an end point (by you're own definition)?</p>