title: When does Socket.Receive return the data?
body: <p>Beginner Question again: Kind of a follow up to a question I asked not long ago.</p>
  
  <p>I am trying to understand this synchronous socket tutorial <a href="http://msdn.microsoft.com/en-us/library/6y0e13d3.aspx">http://msdn.microsoft.com/en-us/library/6y0e13d3.aspx</a>, particularly one single line in the code below. </p>
  
  <p><strong>QUESTION:</strong> 
  I want to make sure I am understanding the program flow right . <strong>When</strong> does handler.Receive(bytes) return? Does it return and store the number of bytes received in <strong>int bytesRec**when it "overflows" and has received more than 1024bytes? **And if that is so</strong>, and this might sound silly, what happens if MORE bytes arrive as it is storing the 1024 bytes in the *<em>data</em>*variable and not listening for more bytes that might be arriving at that time? Or should I not worry about it and let .net take care of that?</p>
  
  <pre><code>Socket handler = listener.Accept();
  data = null;
  
  // An incoming connection needs to be processed.
  while (true) {
      bytes = new byte[1024];
      int bytesRec = handler.Receive(bytes);
      // My question is WHEN does the following line
      // get to be executed
      data += Encoding.ASCII.GetString(bytes,0,bytesRec);
      if (data.IndexOf("&lt;EOF&gt;") &gt; -1) {
          break;
      }
  }
  </code></pre>