Hello!
I'm trying to code a C# server for flash apps, and I'm currently working on a broadcast function. When flash clients connect to the server they are added to the connClients list (List<TcpClient>), and with the following function I send the stuff to my flash apps:
public void sendToClient(String line, TcpClient client)
{
NetworkStream clientStream = client.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)
{
sendToClient(line,connClients[i]);
}
else
{
connClients.Remove(connClients[i]);
myInterface.logTxt.AppendText("Client disconnected."+ Environment.NewLine);
}
}
myInterface.logTxt.AppendText("Message broadcasted to " + connClients.Count.ToString() + " clients." + Environment.NewLine);
}
The problem is, I can use the sendToClient function on one specific client, but the broadcast doesn't work. It says the message is submitted to the right number of clients, but I never recieve anything. No error messages, no nothing.
Anyone?