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;
精彩评论