2
読み込みバッファに問題があり、読み込みが完了していない場合。BeginReceiveで複数の部品を受け取る方法は?
受信したXMLデータが有効な場合は問題ありません。しかし、受け取ったXMLデータが正しくなければ、データの2番目の部分を待っています。そこでエラーが発生します。
私のコードは次のようになります。
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);
}
にはどうすれば残りのデータを取得することができますし、どのように私は正しくオフセット使うのですか?あなたはの配列を必要とするので、オフセットあなたがオフセット使用する場合は、受信データを指定で始まるバッファに格納されます
specified argument was out of the range of valid values. parameter name : size
はあなたに壊れありがとうを、もう一つの問題は、それを行うには良い方法はありますか? – Racooon
一般的にデータは任意の数のチャンクで*受信できます*すべてのデータを受信するまでは 'BeginReceive'を呼び出さなければなりません。 – BrokenGlass