How to get current bandwith speed using IdTCPServer or IdTCPClient ?
I want to know, how fast client is downloading data from server ?
e.g.: Downloading speed: 450 kbps
Assign handlers to the OnWorkBegin
, OnWork
, and OnWorkEnd
events of the connection's TIdTCPConnection
object. The OnWorkBegin
event has an AWorkCountMax
parameter that gives you the total expected bytes being transfered (if known ahead of time). The OnWork
event has an AWorkCount
parameter that gives you a running total of how many bytes have actually been transferred since the OnWorkBegin
event was fired.
Whenever the OnWork
event is fired, subtract the previous AWorkCount
value from the current AWorkCount
value to determine how many bytes have been transferred between the two events, and then divide that value by the amount of time that has elapsed between the two events. With that final value, you can calculate b/sec, kb/sec, mb/sec, etc as needed.
Depending on how exactly you are sending/receiving your data, you may have to manually call the BeginWork()
and EndWork()
methods of TIdTCPConnection
to get the OnWork...
events to start firing. Most of Indy's read/write methods do not call Begin/EndWork()
internally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With