I have a client part, which consist of 2 threads, one for reading from
a networkstream and one for writing to a networkstream, somehow my
reading does not work:
////Code
private static void readFromServer()
{
StreamReader sr = new StreamReader(clientStream);
while (true)
{
Console.WriteLine("Check if data is available");
if (clientStream.DataAvailable)
{
Console.WriteLine("Data was available");
while (sr.Peek() != -1)
{
Console.WriteLine("Starts to read:");
Console.WriteLine(sr.ReadToEnd());
Console.WriteLine("Done!");
}
}
Thread.Sleep(1000);
}
}
//// code
What's not working is the sr.ReadToEnd , I have also tried readline.
What works is sr.Read which reads but then the second time around(next
message) is not accepted, why is this?
Thank you in advance.