Calculate latency
Posted: 02 Apr 2012, 17:48
Hi,
I'm trying to display the latency on my client, but I can't get it to work properly. I searched on this forum and I found you guys recommend to use the lagmonitor in combination with the PingPong event. However, I can't find this in the iOS API.
Right now I calculate the latency by adding a unix timestamp to my packages sent from the server with:
On client side I read this timestamp, and compare it with the current time on the client:
This should work, since I'm using the unix timestamps to calculate the latency. The result of this calculation is always +- 2750ms, which isn't correct (local network + network communication feels very responsive). Am I doing something wrong? Or are there better ways to do this?
Thanks
I'm trying to display the latency on my client, but I can't get it to work properly. I searched on this forum and I found you guys recommend to use the lagmonitor in combination with the PingPong event. However, I can't find this in the iOS API.
Right now I calculate the latency by adding a unix timestamp to my packages sent from the server with:
Code: Select all
System.currentTimeMillis()
On client side I read this timestamp, and compare it with the current time on the client:
Code: Select all
// Extract the timestamp from the message
double timestamp = [[dictionary objectForKey:TIMESTAMP_KEY] doubleValue];
// Calculate the latency
NSNumber *systemTimestamp = [NSNumber numberWithDouble:1000.0 * [[NSDate date] timeIntervalSince1970]];
int latency = (int) ([systemTimestamp doubleValue] - timestamp);
This should work, since I'm using the unix timestamps to calculate the latency. The result of this calculation is always +- 2750ms, which isn't correct (local network + network communication feels very responsive). Am I doing something wrong? Or are there better ways to do this?
Thanks