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:
- Start server
- Connect Client1, Client2
- Client1 sends message "a" ... nothing happens
- Client1 sends message "b" ... nothing happens
- Client2 sends message "c" ... both clients got "ac"
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:
- in client program there is some server ( it's old overwritten project )
- I create for every clients new Reader and Writer Stream; I got to know that I can use one R/W Stream but I couldn't use it however.. Because I use List list so: reader(list.getByte()) does't work.
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.