Measuring network traffic in C#

Alxandr picture Alxandr · Mar 28, 2012 · Viewed 7.3k times · Source

I'd like my application to be able to monitor how much data (I don't need the actual packages, only amount of bytes) that goes in an out of the computer (on a single interface) at all time, and also over time. In other words; I want to be able to show a number displaying current up and down speed (for instance 5kB/s) as well as a graph over the last 5 minutes, and lastly I also want to be able to show a correct amount of data that has gone out/in of the interface in the last hour.

Is this doable in a simple manner? I don't mind using third-party assemblies, or having to write my own wrapper around some win32 api, however; said third-party assemblies must be able to be used with open-source applications and must not cost money.

Answer

daryal picture daryal · Mar 28, 2012

In fact you may easily get all network traffic using performance counters, but I do not know any way to measure network traffic of your application than opening each packet and reading it. To measure all network traffic, refer to the following:network traffic in c#