TCP server idle time

Sharma, Shivani 1 Reputation point
2021-03-05T06:49:13.567+00:00

Looking for a way to identify if a TCP server port is idle or not.. and If so, for how long the port is in idle state. Are there any direct Microsoft APIs or some way to indentify this?

Developer technologies C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,651 Reputation points
    2021-03-08T05:57:26.897+00:00

    Hi SharmaShivani-9342,
    You can try to use TcpClient to check the TCP ports.
    And please refer to this thread for more details.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. cheong00 3,486 Reputation points Volunteer Moderator
    2021-03-11T06:55:15.933+00:00

    Converting to answer because character limit exceed.

    The application itself should be the one responsible to report how it uses the TCP connections. Imagine a typical web or P2P sharing server can have thousands of connection at any given time, if Windows need to keep track of the usage pattern, the server will be sluggish even if the number of connection is low. Now think about that again if the connections are short and the server have to keep connecting and closing them rapidly.

    If the application does not implement usage reporting functions, the best you can do is to use GetTcpTable2() API to gather open connection status, and then call GetPerTcpConnectionEStats() / GetPerTcp6ConnectionEStats() API on each of the connections you're interested in to get the estimation.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.