Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current bandwidth (download) speed ?

Tags:

delphi

indy

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

like image 782
jmp Avatar asked Dec 28 '11 00:12

jmp


1 Answers

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.

like image 138
Remy Lebeau Avatar answered Sep 22 '22 01:09

Remy Lebeau