Hi all, I utilize TcpClient class to implement a telnet connection. What I don't know is how to determine the end of response. It seems that once DataAvailable property is true, I read the data from Stream and DataAvailable is then temporarily set to false while buffer is being filled with another chunk of data but I think is all read and go away. How do I ensure that all response was read?
You might advise me how to change the code snippet below to make this work correctly. It works correctly when I step through the code because there is plenty of time for the whole response to be retrieved. Appreciate your help.
if (this.Stream.DataAvailable)
{
readBuffer = new Byte[this.Client.ReceiveBufferSize];
do
{
// read data
bytes = this.Stream.Read(readBuffer, 0, readBuffer.Length);
Thread.Sleep(10);
responseData = String.Concat(responseData, System.Text.Encoding.ASCII.GetString(readBuffer, 0, bytes));
} while (this.Stream.DataAvailable);
allDataRead = true;
break;
}