No_Name
جمعه 25 آذر 1390, 03:05 صبح
سلام
من یه برنامه چت ساختم ولی تو یه قستمی بد جور هنگم :عصبانی++:
تا اینجاش پیش رفتم که کلاینت ها به سرور وصل میشن و میتونن به سرور پیغام ارسال کنن
ولی نمیدونم چطور میشه که سرور تمامی کلاینت ها رو یک جا جمع کنه و سپس پیغامی که مثلآ از طرف کلاینت A میاد رو به همه ی کلاینت ها ارسال کنه
فقط فقط فقط توی همین قسمتش موندم !:افسرده:
خودم اومدم اینکار رو کردم و این کد رو نوشتم ولی جواب نداد:
1- یه سوکت تعریف کردم:
public Socket client;
2- برای گرفتن تمامی کلاینت ها از این استفاده کردم:
private static Dictionary<int, Socket> allSocket = new Dictionary<int, Socket>();
3- کلاینت هایی که به سرور وصل میشن رو توی allsocket اضافه کردم:
private static int rand = 0; int id = 0; rand++; id = rand; allSocket.Add(rand, client);
4- خب الان هم برای ارسال پیغام به تک تکه کلاینت هایی که توی allsocket اضافه شدن رو از این کد استفاده کردم:
for (int i = 0; i < id ; i++) { allSocket[id].Send(Encoding.Unicode.GetBytes("Test Send Msg")); }
کسی میتونه بگه کجاش مشکل داره ؟ میتونین واسم درستش کنین ؟
چند هفتس فقط توی همین قسمتش گیر کردم
نمیخوام لینک سورس مورس بهم بدین، زیاد سورس باز کردم و هر کدام هم به یه روش نوشته بودن :|
یه روش از همه کاربردی تر رو میخوام بهم بگین
----> فقط در همین قستمی که مشکل دارم رو توضیح بدین
تشکر
من یه برنامه چت ساختم ولی تو یه قستمی بد جور هنگم :عصبانی++:
تا اینجاش پیش رفتم که کلاینت ها به سرور وصل میشن و میتونن به سرور پیغام ارسال کنن
ولی نمیدونم چطور میشه که سرور تمامی کلاینت ها رو یک جا جمع کنه و سپس پیغامی که مثلآ از طرف کلاینت A میاد رو به همه ی کلاینت ها ارسال کنه
فقط فقط فقط توی همین قسمتش موندم !:افسرده:
خودم اومدم اینکار رو کردم و این کد رو نوشتم ولی جواب نداد:
1- یه سوکت تعریف کردم:
public Socket client;
2- برای گرفتن تمامی کلاینت ها از این استفاده کردم:
private static Dictionary<int, Socket> allSocket = new Dictionary<int, Socket>();
3- کلاینت هایی که به سرور وصل میشن رو توی allsocket اضافه کردم:
private static int rand = 0; int id = 0; rand++; id = rand; allSocket.Add(rand, client);
4- خب الان هم برای ارسال پیغام به تک تکه کلاینت هایی که توی allsocket اضافه شدن رو از این کد استفاده کردم:
for (int i = 0; i < id ; i++) { allSocket[id].Send(Encoding.Unicode.GetBytes("Test Send Msg")); }
کسی میتونه بگه کجاش مشکل داره ؟ میتونین واسم درستش کنین ؟
چند هفتس فقط توی همین قسمتش گیر کردم
نمیخوام لینک سورس مورس بهم بدین، زیاد سورس باز کردم و هر کدام هم به یه روش نوشته بودن :|
یه روش از همه کاربردی تر رو میخوام بهم بگین
----> فقط در همین قستمی که مشکل دارم رو توضیح بدین
تشکر