How to receive multiple parts with BeginReceive?
<p>I have problem with reading buffer, when reading is not completed.</p>

<p>If the received XML data is valid, then I have no problem. But when the received XML data is not correct then I am waiting for the second part of the data, and there I get an error.</p>

<p>My code looks like:</p>

<pre><code>int currentDataSize = socket.EndReceive(iar);
string currentData  = convertToString(buffer, currentDataSize);

if (IsValidXml(currentData))
{
  //Here I am parsing the xml data and writing into the sql db.
  runParseWorker(currentData);      

  //Here I am sending the xml-data to all clients.
  runSendWorker(currentData);

  //Here I am calling the BeginRecieve Method again.
  socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, 
                      new AsyncCallback(dataRecievedCallback), null);
}
else
{ 
  //It gives error when I use offset..
  socket.BeginReceive(buffer, currentDataSize, buffer.Length, SocketFlags.None, 
                      new AsyncCallback(dataRecievedCallback), buffer);
}
</code></pre>

<p>How can I get the rest of the data and how do I use offset correctly?</p>

<p>I am getting this error:</p>

<pre><code>specified argument was out of the range of valid values. parameter name : size
</code></pre>
