开发者

Get a number of open sockets in C#?

开发者 https://www.devze.com 2023-01-19 05:09 出处:网络
I\'m trying to log the number of open sockets in my C# server application. Like the info you could get from \"netstat -s\":

I'm trying to log the number of open sockets in my C# server application. Like the info you could get from "netstat -s":

TCP Statistics for IPv4

  Active Opens                        = 22765
  Passive Opens                       = 9316

I coul开发者_JAVA百科d parse the result from "netstat".. but if there's a class for it, then why would I..

By the way, with the help of class System.Diagnostics.Process, I could log a number of handles, and threads. I thought that a socket is a handle, but it seems not.. In my situation, the # of handles was way below # of active connections from netstat.

Any suggestions, advices or answers will be greatly appreciated. Thank you :)


Have a look at the TcpStatistics Class.

For example, the TcpStatistics.CurrentConnections Property returns "The number of TCP connections for which the current state is either ESTABLISHED or CLOSE-WAIT."

long result = IPGlobalProperties.GetIPGlobalProperties()
                                .GetTcpIPv4Statistics()
                                .CurrentConnections;
0

精彩评论

暂无评论...
验证码 换一张
取 消