インターネットから、NetworkStream から巨大な文字列を読み取る方法を手に入れました。
static NetworkStream ns = null;
static StringBuilder sb = null;
static byte[] buffer = null;
static int position = 0;
//.......................................
//other codes skipped for simplicity
//.......................................
private static string Read()
{
if (ns.CanRead)
{
sb.Clear();
position = 0;
while (ns.DataAvailable)
{
position = ns.Read(buffer, 0, buffer.Length);
sb.Append(Encoding.Unicode.GetString(buffer, 0, position));
}
return sb.ToString().Trim();
}
else
{
return null;
}
}
ただし、巨大な文字列を NetworkStream に書き込む方法の例が見つかりません。
読むのと同じように、書くのに「対称的な」パターンはありますか?
前もって感謝します。