I'm making a C# server for flash clients using TcpClients and listeners. I got the whole thing working when using just one TcpClient, I can send to and recieve from it. Now I'm working on a function to broadcast a message to all the TcpClients, which I've added to a List. It says it sent but in fact I don't recieve anything on my flash apps. Does anybody know what's wrong?
Here's the bit of code that broadcasts it, it's just the single client message for each client.
Here's the bit of code that broadcasts it, it's just the single client message for each client.
Code:
public void sendToClient(String line) { NetworkStream clientStream; clientStream = activeClient.GetStream(); ASCIIEncoding encoder = new ASCIIEncoding(); byte[] buffer = encoder.GetBytes(line + "\0"); clientStream.Write(buffer, 0, buffer.Length); clientStream.Flush(); } public void broadcast(String line) { for (int i = 0; i < connClients.Count; i++) { if (connClients[i].GetStream().CanWrite) { activeClient = connClients[i]; sendToClient(line); } else { connClients.Remove(connClients[i]); myInterface.logTxt.AppendText("Client disconnected."+ Environment.NewLine); } } myInterface.logTxt.AppendText("Message broadcasted to " + connClients.Count.ToString() + " clients." + Environment.NewLine); }
Comment