This project is read-only.

SendToAll() for the sub protocol sample

Oct 1, 2010 at 9:45 PM
Edited Oct 1, 2010 at 9:51 PM

Hi, great application! I'm new to C# and would like to use your server as a basic client chat service. How can I modify the SubProtocol sample server so that it broadcasts input from one connected client to all the other connected clients? I noticed you have a SendToAll function in your console app demo that broadcasts the input from the console, I suspect all I would need a reference to the base WebSocketServer Connections property within the Incoming method in ConsoleAppSocket but don't know how to achieve this. Or is there another way?

Thanks in advance!

Tom D.

Oct 3, 2010 at 3:51 PM

Thats one of the things that I would like to improve, a way for clients to communicate. If you have any idea as how that should be done that would be great.

To solve your problem you need to store all the connected clients, and send to all of them individually. You can do this by having I static list in the handler class, and add the clients to it in the "connected" method. And remote them from the list in the "disconnected" method. To broadcast you just send the message to all the clients in the list.

Hope this helps.

Den 01/10/2010 22.45 skrev "tduggin" <notifications@codeplex.com>:

From: tduggin

Hi, great application! I'm new to C# and would like to use your server as a basic client chat service. How can I modify the SubProtocol sample server so that it broadcasts input from one connected client to all the other connected clients? I noticed you have a SendToAll function in your console app demo that broadcasts the input from the console, but I'm looking to create more of a client chat service.

Thanks in advance!

Tom D.

Read the full discussion online.

To add a post to this discussion, reply to this email (nugget@discussions.codeplex.com)

To start a new discussion for this project, email nugget@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Oct 3, 2010 at 6:19 PM

Ok, great. I've done a similar implementation in a TCP socket server for managing the client connections , thanks for the tip!

Oct 3, 2010 at 6:51 PM

follow up... I added the static connections list as you suggested and copied in your SendToAll method and it seems work just fine. Thanks again.

Jan 30, 2011 at 12:32 PM
Edited Jan 30, 2011 at 12:46 PM

Hi!

That's almost the way I'd like to use the websocket server. But is there any possibility to figure out which connection invoced the incoming method? I would like the server just to answering several clients individually. Is it possible?

Thanks in advance!