简体   繁体   中英

How do i measure how much data has been sent over a C# socket

I'm building an application that needs to charge users based on the exact bandwidth used by their connections.

I could of course keep track of how many bytes i pass to/from send/receive but that doesn't include IP packet overhead which i'd very much like to include since we're talking lots of small packets of varying size.

I could estimate it, but i'm curious if there is a relatively simple cheep way of knowing.

For instance, in windows server 2008 there is a dialog that shows bandwidth usage pr. connection; perhaps it's possible to access this information?

该问题的答案使用PerformanceCounter监视带宽,并且可能对您要执行的操作有所帮助。

From memory you might find the PerformanceCounter class in the System.Diagnostics namespace able to provide you with the information you want.

Failing that WMI has a large array of information about the computer

And my last thought but by no means an atractive one, get a sniffer and have a service analyse its results every hour or so. remember to delete the sniffers output when you have what you need they can get quite big.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM