You need
str.CopyTo(data);
data.Position = 0; // reset to beginning
byte[] buf = new byte[data.Length];
data.Read(buf, 0, buf.Length);
And since your Test()
method is imitating the client it ought to Close()
or Dispose()
the str
Stream. And the memoryStream too, just out of principal.