المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Improve Speed of send message from server to all Clients



C# Programming
07-12-2009, 10:00 PM
I write new application server/client. I use TcpClient. When my server is listening and allow many computers connect. Example : My server have 50 computers client connected. I have problem when I want to send 1 message to all clients, I must use FOR/NEXT therefore It cost 5 seconds or more to send 1 message to 50 Computers client. Now I want to improve speed of send message, Please give me advice.

Please see code below

//Send Admin Message
public static void sendAdminMessage(string sMessage)
{

//ArrayList LIST_CLIENT contain all connections of client
if (LIST_CLIENT.Count > 0)
{
Object []arr = LIST_CLIENT.ToArray();
for (int i = 0; i < arr.Length; i++)
{
try
{
MyClient client = (MyClient)arr[i];
send(client.TcpClient, sMessage);
}
catch(Exception e) {
Console.WriteLine(e.Message);
}
}
}
}