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

مشاهدة النسخة كاملة : TcpClient does not get disconnected?



C# Programming
11-01-2009, 05:40 PM
How to notify TcpClient that it is disconnected?

1. I start async TcpListener
2. Once the client is connected it reads all data it sent also in async mode
3. Then simply close NetworkStream and close the client connection


private void TcpListenerDataReadAsyncCallback(IAsyncResult ar)
{
TcpClient tc = (TcpClient)ar.AsyncState;
NetworkStream ns = tc.GetStream();

//read all client data

ns.Close();
tc.Close();
}


In the client console, I wait in the loop with small sleeps for a long long while to wait if the server will send somthing, testing tcpClient.Connected property.
But it never becomes false???

????????