Get some open sockets in C #?

I am trying to register the number of open sockets in my C # server application. Like the information you can get from "netstat -s":

TCP Statistics for IPv4 Active Opens = 22765 Passive Opens = 9316 

I could analyze the result from "netstat" .. but if there is a class for it, then why should I ..

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

Any suggestions, tips or answers are welcome. Thanks:)

+6
c # sockets
source share
1 answer

Check out the TcpStatistics class .

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

 long result = IPGlobalProperties.GetIPGlobalProperties() .GetTcpIPv4Statistics() .CurrentConnections; 
+5
source share

All Articles