I have a project that contains a C# console app, and a client WPF app. The goal is to have any one client write to the server, then the message is sent to all connected clients from the server. Currently, I can get many clients to connect to the server using threads on the server side. The problem is that when any client sends a message, only that same client receives the message back from the server. I've tried looking for help online but can't find anything that helps me communicate from the server to all clients.
I've tried to create a list of connected threads, and used a foreach() loop to send the message to all threaded clients, but it didn't work.
Any tips/help/ideas are welcome. I'm not looking for straight answers necessarily, maybe just help with what's needed to do it, and the sequence of events that need to happen.
Thanks
What I have tried:
server basics:
-wait for client to connect
-ifConnected -> create thread for connection
-put thread in a list
-in method for thread: loop ->
-receive streamreader input from client
-in foreach loop: write client message to server console, and use streamwriter to send
the message to all threaded clients in foreach loop
client basics (WPF):
-user types in message
-when user clicks on send button:
- use streamwriter to send message to server
- use streamreader to get message back from server
- display in textblock the messages from the server