views:

36

answers:

1

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 could 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 :)

+1  A: 

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;
dtb
you rock!!! thank you :)
wooohoh
by the way, for people who don't want to look up the link... it's System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().GetTcpIPv4Statistics()
wooohoh