title: How do I know when an asynchronous socket read ends?
body: <p>I have an asynchronous read method...</p>
  
  <pre><code>private void read(IAsyncResult ar) {
          //Get the Server State Object
          ServerState state = (ServerState)ar.AsyncState;
  
          //read from the socket
          int readCount = state.socket.EndReceive(ar);
  
          //check if reading is done, move on if so, trigger another read if not
          if (readCount &gt; 0) {
              //purge the buffer and start another read
              state.purgeBuffer();
              state.socket.BeginReceive(state.buffer, 0, ServerState.bufferSize, 0, new AsyncCallback(read), state);
          }
          else {
              //all bytes have been read, dispatch the message
              dispatch(state);
          }
      }
  </code></pre>
  
  <p>The problem that I am having is that <i>read</i> is only 0 if the connection is closed. How do I say, this is the end of that message and pass the data on to the dispatcher, while leaving the socket open to accept new messages.</p>
  
  <p>Thank you!</p>