Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 10-Dec-17 21:09pm
Comments
PureNsanity 13-Dec-17 17:02pm    
Is there a reason you have to use, or are limited to, named pipes?

1 solution

One solution (simplest) - clients should have timer, and try to read from server messages every 1 second (or less, or more - according business demands).

Second - each client should be also server for main, and when main will have message from one client, it should broadcast this message to all connected clients, using its servers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900