简体   繁体   English

NetworkStream.Read下载进度。 类似于WebClient.DownloadProgressChanged

[英]NetworkStream.Read download progress. In similar to WebClient.DownloadProgressChanged

I want to know current download progress when im using NetworkStream.Read. 我想知道当前使用NetworkStream.Read时的下载进度。 Is it even possible? 可能吗 Do i have to use webclient? 我必须使用webclient吗?

I dont want to use webclient because it seems(im not 100% sure) 我不想使用webclient,因为它似乎(不是100%确定)

  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. 由于http协议的限制,我无法正确衡量千兆网络的传输速度。

or, i should use webclient? 或者,我应该使用webclient?

FYI, Im building bandwidth estimation tools. 仅供参考,我正在构建带宽估算工具。

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 循环调用“ stream.Read(buffer,0,buffer.Length);`,直到获得足够的字节来计算适当的速率为止
  3. Take end time 结束时间
  4. Divide the received byte length with number of seconds it took download them. 将收到的字节长度除以下载它们所花费的秒数。
  5. Result = bytes/s 结果=字节/秒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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