Hi all,
From the internet I got the way to read a huge string from a 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;
}
}
However, I cannot find an example how to write a huge string to a NetworkStream.
Is there a "symmetrical" pattern for writing as we do for reading?
Thank you in advance.