PDA

View Full Version : سوال: دریافت طلاعات از کاربر توسط tcplistner



mahdi bg
شنبه 31 اردیبهشت 1390, 16:41 عصر
سلام
من یک برنامه سرور کلاینت دارم

در سمت سرور



public Listener()
{


tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 5000);
threadtcpListener = new Thread(new ThreadStart(ListenForClients));
threadtcpListener.Start();

}

public void ListenForClients()
{
tcpListener.Start();
while (true)
{
TcpClient tcpClient = tcpListener.AcceptTcpClient();
Thread threadtcpClient = new Thread(new ParameterizedThreadStart(HandelCLient));
threadtcpClient.Start(tcpClient);
}
}


سمت کلاینت هم این کد رو دارم

for (int i = 0; i < 1000; i++)
{
SendMSG = new Thread(new ThreadStart(SendMSGFunction));
SendMSG.Start();
داخل این thread پیام برای سرور فرستاده میشه
}

مشکل اینجاست با اینکه برای هر درخواست کاربر در سمت سرور یک thread می سازم
اما بعضی مواقع هر 2 یا 3 تا پیامی که کاربر می فرسته با هم دریافت میشه
چطوری میشه برای هر پیام یک thread ساخت؟