Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TcpClient doesn't close connection

TcpClient doesn't close connection

Scheduled Pinned Locked Moved C#
helpcsharpdotnetsysadminperformance
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ehuysamer
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • E 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

      A Offline
      A Offline
      Arun Bhalla
      wrote on last edited by
      #2

      If you call TcpClient.GetStream(), you also need to close the Stream in addition to the TcpClient.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups