I'm working on a real-time HTML5 game with C# server side.
With the help of the Alchemy Websocket Library, it's quite easy to setup the websocket server in using C#. But the Alchemy Websocket's Official documentation didn't mention about the broadcast function.
I'm going to use the Namespace Socket to put the tcp connection(socket object?) into a list, then using foreach to traverse the list and sending the data to the member in the list when the server received the data. Is it feasible? My code seems incorrect. But I'm trying to fix the bugs instead of putting the code here and just waiting.
Anyone can give some suggestions or examples about the tcp broadcasting in using C#?
Thanks in advance.
I do not understand the part about using the "Namespace Socket". However you do not need to access the underlying TCP sockets.
You will have to maintain a list of connected WebSockets, and then iterate over them sending the data you want to broadcast. There are events in Alchemy that tells you when a client connects or disconnects, use them to maintain such list. Lock the list before adding/removing.
There is an example in the Alchemy documentation: https://github.com/Olivine-Labs/Alchemy-Websockets-Example/blob/master/Server/src/Program.cs