Search code examples
c#httpwebclientbandwidthnetworkstream

NetworkStream.Read download progress. In similar to WebClient.DownloadProgressChanged


I want to know current download progress when im using NetworkStream.Read. Is it even possible? Do i have to use webclient?

I dont want to use webclient because it seems(im not 100% sure)

  1. i have to create webserver
  2. i have to create file (instead of memory stream data).
  3. i cannot properly measure transfer speed of gigabit networks, due to http protocol limitation.

or, i should use webclient?

FYI, Im building bandwidth estimation tools.


Solution

  • What's the problem?

    1. Get the current time
    2. Invoke ´stream.Read(buffer, 0, buffer.Length);` in a loop until you get enough bytes to calculate a proper rate
    3. Take end time
    4. Divide the received byte length with number of seconds it took download them.
    5. Result = bytes/s