How to get the current bandwidth (download speed)?

How to get current bandwidth using IdTCPServer or IdTCPClient?

I want to know how fast the client downloads data from the server?

For example: Download speed: 450 kbps

+6
source share
1 answer

Assign handlers to the OnWorkBegin , OnWork and OnWorkEnd events of the OnWorkBegin connection TIdTCPConnection . The OnWorkBegin event has an OnWorkBegin parameter that gives you the total number of bytes expected (if known in advance). The OnWork event has an OnWork parameter that gives you the total number of how many bytes have actually been transferred since the OnWorkBegin event was OnWorkBegin .

Each time the OnWork event OnWork subtract the previous AWorkCount value from the current AWorkCount value to determine how many bytes were transmitted between the two events, and then divide this value by the amount of time that passed between the two events. With this final value you can calculate b / sec, kb / sec, mb / sec, etc. As needed.

Depending on how you send / receive your data, you may need to manually call the BeginWork() and EndWork() TIdTCPConnection so that the OnWork... events start firing. Most Indy read / write methods do not call Begin/EndWork() internally.

+9
source

Source: https://habr.com/ru/post/904565/


All Articles