I have a client which talks to a server, the code below is supposed to print on the console what was typed in - this spans over multiple lines.
The problem is that it displays all the lines, then throws an exception.
I have tried different ways in order to get this to work such as peek()
which causes the final line to be cut off and the same exception to be thrown.
Is there something I am missing?
using (sr)
{
try
{
while (!sr.EndOfStream)
{
Console.WriteLine(sr.ReadLine());
}
}
finally
{
sr.Close();
}
}
The exception is: System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
I have used .ReadTimeout
and .WriteTimeout
just before the using (sr)