...基本的にはタイトルが言うとおりです。 NetworkStream.Lengthは実装されていません。代替手段は何ですか?.NET NetworkStream.Lengthの回避策のサポートがありません
私はNetworkStream.BeginRead(...)の呼び出しを囲む非同期コールバックの再帰的なシリーズを作ろうとしています。いつ私のベースケースに当たって、すべてのバイトを受け取ったのかを知るためには、ストリーム内のバイトの長さを知る必要があります。このための回避策はありますか?
コード(このコードへのエントリポイントは、タイトルが言う基本的にはまさに... TcpListern.BeginAcceptTcpClientコール:
private void StartRead(IAsyncResult ar)
{
try
{
//Do an initial read:
AsyncClient client = (AsyncClient)ar.AsyncState;
int amountRead = 0;
try
{
amountRead = client.ClientStream.EndRead(ar);
}
catch (IOException io)
{
ProcessDebugLog("Async read complete", io);
client.ClientStream.Close();
return;
}
string text = Encoding.UTF8.GetString(client.Bytes, 0, amountRead);
//If TCP segmentation has occurred, more blocks will have
// to get read in:
if (client.ClientStream.Position < client.ClientStream.Length /*EXCEPTION HERE*/)
{
try
{
client.ClientStream.BeginRead(client.Bytes, 0, client.Bytes.Length, StartRead, client);
}
catch (IOException io)
{
ProcessDebugLog("Async read complete", io);
client.ClientStream.Close();
}
}
else
{
client.ClientStream.Close();
}
}
catch (Exception ex)
{
ProcessDebugLog("ERROR - StartRead", ex);
}
}
接続の両側を制御しますか? –
一部のストリームは実際にストリームです。水がなくなるまで、あなたはその川にどれくらいの水があるのか分かりません。 –
@Booはい私は両側を制御します。 – kmarks2