TcpClient doesn't close connection
-
Hi I was wondering if anyone familiar with the workings of the .NET TcpClient and TcpListener classes could help. The problem is that closing TcpClient connections doesn't actully seem to close them, according to the performance counter "NET CLR Networking -- Connections Established": the count just gets higher and higer - it doesn't even come down when I restart the applications Now, for a simple test case, I have a server component with TcpListener: TcpListener listener = new TcpListener(PORT); TcpClient client; for (;;) { if (listener.Pending) { client = listener.AcceptTcpClient(); Console.WriteLine("Connection established"); client.Close(); } } A client opens up a connection, sleeps for one second and then closes it. On a live system, as the connection count gets higher, the data transfer rate gets lower and lower until it eventually stops and the W2K workstation has to be restarted. Any ideas on how I can fix this and force these connections to close? thanks ehuysamer
-
Hi I was wondering if anyone familiar with the workings of the .NET TcpClient and TcpListener classes could help. The problem is that closing TcpClient connections doesn't actully seem to close them, according to the performance counter "NET CLR Networking -- Connections Established": the count just gets higher and higer - it doesn't even come down when I restart the applications Now, for a simple test case, I have a server component with TcpListener: TcpListener listener = new TcpListener(PORT); TcpClient client; for (;;) { if (listener.Pending) { client = listener.AcceptTcpClient(); Console.WriteLine("Connection established"); client.Close(); } } A client opens up a connection, sleeps for one second and then closes it. On a live system, as the connection count gets higher, the data transfer rate gets lower and lower until it eventually stops and the W2K workstation has to be restarted. Any ideas on how I can fix this and force these connections to close? thanks ehuysamer
If you call TcpClient.GetStream(), you also need to close the Stream in addition to the TcpClient.