none
New TCPClient(server,port) Constructor Slow on 64-bit Computers RRS feed

  • General discussion

  • The tcpClient in System.Net.Sockets has four constructors. One of the most convenient is New tcpClient(server, port) to instantiate a connection to a specific host and port. On several different 64-bit computers the connect time was very slow, ranging from 1.5 seconds to 7 seconds when using that constructor. Tests were conducted on Windows 7 SP2, Windows 8, Windows 8.1, and Server 2008 R2.

    Additional tests were done on 32-bit computers including Server 2003 and Server 2008 Standard SP2. In every case connect times were under a second, and in some cases just a few milliseconds.

    By changing to a two-step connect starting with the generic constructor, in every case (64-bit and 32-bit) the connection was made in 1 to 5 milliseconds.

    oTCP = New tcpClient()

    oTCP.Connect(sHost, iPort)

    The most dramatic change was on the Server 2008 R2 (2.5GHz Xeon) which went from 6 or 7 seconds to a couple of milliseconds. No other changes were made.

    Monday, February 3, 2014 10:40 PM

All replies

  • The tcpClient in System.Net.Sockets has four constructors. One of the most convenient is New tcpClient(server, port) to instantiate a connection to a specific host and port. On several different 64-bit computers the connect time was very slow, ranging from 1.5 seconds to 7 seconds when using that constructor. Tests were conducted on Windows 7 SP2, Windows 8, Windows 8.1, and Server 2008 R2.

    Additional tests were done on 32-bit computers including Server 2003 and Server 2008 Standard SP2. In every case connect times were under a second, and in some cases just a few milliseconds.

    By changing to a two-step connect starting with the generic constructor, in every case (64-bit and 32-bit) the connection was made in 1 to 5 milliseconds.

    oTCP = New tcpClient()

    oTCP.Connect(sHost, iPort)

    The most dramatic change was on the Server 2008 R2 (2.5GHz Xeon) which went from 6 or 7 seconds to a couple of milliseconds. No other changes were made.

    Did you try compiling to x86 or x64 CPU rather than AnyCPU to see if that changes anything?


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Monday, February 3, 2014 10:43 PM