Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jul : Download Speed
| Subject: | Download Speed |
| Posted by: | "Sümer Cip" (sume..@softhome.net) |
| Date: | Mon, 10 Jul 2006 00:40:09 |
Hi,
I want to calculate the download speed of a file which is being downloaded
using TIdHTTP.Get.
I use OnWork event to calculate the data readed.My code seems to work but,
it is always changing 25 to 8 KBPS, 10 to 25, it is changing very fast.What
I expected is a fixed download speed(Because NetLimiter shows a fixed value
and my calculation alg. always shows different value.).Here is the code:
procedure TDownloadThread.OnWork(ASender: TObject;
AWorkMode: TWorkMode; Const AWorkCount: Integer);
function CalculateSpeedPerSec(curr,pre:Integer;BufLen:Integer):Double;
begin
if curr = pre Then
curr := curr+1;
Result := (BufLen / (curr-pre))*1000;
end;
begin
if Not Assigned(fStream) Then
exit;
if AWorkMode = wmRead then
begin
fCurrentTick := GetTickCount;
VirtualTreeData^.SpeedPerSec :=
CalculateSpeedPerSec(fCurrentTick,fPreviousTick,AWorkCount-fPreviousWorkCount);
VirtualTreeData^.FilePosition := AWorkCount;
if VirtualTreeData^.FileSize <> 0 Then
VirtualTreeData^.DownloadedPercentage := (100 * (AWorkCount)) /
VirtualTreeData^.FileSize;
if ((fCurrentTick-fPreviousTick) >= 1000) and (fStream.Position <> 0)
Then
Synchronize(UpdateGUI);
fPreviousTick := fCurrentTick;
fPreviousWorkCount := AWorkCount;
end;
end;