Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to track a single download speed with asihttprequest

Can someone help me with asihttprequest ?

I want to track the speed download of each file I download and not the average speed of all the files.

For the average spped of all downloads, there is [ASIHTTPRequest averageBandwidthUsedPerSecond] but what can I use to track each downloads?

Thanks

like image 623
Alby Avatar asked Jun 12 '11 00:06

Alby


1 Answers

Considering ASI is dead, I recently had to do this on an older project. If somebody else needs help:

-(void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes
{
    if (!lastBytesReceived)
        lastBytesReceived = [NSDate date];

    NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:lastBytesReceived];

    float KB = (bytes / 1024);

    float kbPerSec =  KB * (1.0/interval); //KB * (1 second / interval (less than one second))

    NSLog(@"%llu bytes received in %f seconds @ %0.01fKB/s",bytes,interval, kbPerSec);

    lastBytesReceived = [NSDate date];
}
like image 143
skwashua Avatar answered Nov 02 '22 15:11

skwashua