I have written a TCP chat in C# WPF for one client and server (it works). Now I would like to extend this program to have many clients in chat.
client code: http://pastebin.com/Zv1Me6P4
server code: http://pastebin.com/VYBJCA9f
I was checking everything and I guess that streamreader readline fails.
In my program, client sends message to server, which sends to everybody and appears message in their TextBoxs.
How my program works:
Streamreader blocks and I dont know how to unblock it. Okay, I can use new thread; +1 client = +1 thread, but it sounds so strange. I was really reading stackOverFlow and I found sth like: while((line = reader.ReadLine()) != null) or !reader.EndOfStream or reader.pike > 0.. all that doesn't work... or I do it incorrenctly.
Reading my code you can be confused:
I beg you please help me. It's small unsolved piece of my work, which makes me upset. I love programming when problems are resonable and possible to solve.
Thanks for all comment under my post.
I had a similar problem not being able to ReadLine and ReadToEnd would exceed my timeouts. This worked for me
string line = "";
while (reader.Peek() > -1) {
line += (char)reader.Read();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.