I have a client and server program (both in Obj-C) and I am transferring files between two devices using the programs.
The transferring is working fine, but I would
As soon as you start the download, capture the current system time and store it as the "start time". Then, all you need to do to calculate transfer speed at any point during the transfer is to look at the system time again and use it as the "current time" to calculate the total time spent so far:
transfer_speed = bytes_transferred / ( current_time - start_time)
You probably want to use second or millisecond accuracy with the times, and of course can multiply the result by 8 if you want bits/second.
Since you're using Cocoa, you could use the NSDate class to get the timestamps. For example, use the following when you start the transfer:
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
Then periodically check the transfer rate by using:
double speed = bytesTransferred / ([NSDate timeIntervalSinceReferenceDate] - start);