Page 1 of 1
Ping
Posted: 21 Dec 2010, 16:09
by rjgtav
hi. I saw in the whitepapers that the fps example has a ping indicator. How is it measured? Im asking this because i need it in my flash project
Thanks
Posted: 21 Dec 2010, 18:27
by ThomasLund
You can check out the TimeManager class in the Unity code. Basically for a FPS we need to sync time. So the server extension can send the server time to the client. The client then knows its own localtime and can calculate the ping
/Thomas
Posted: 21 Dec 2010, 18:36
by rjgtav
Hum ok. So its easy. Thanks

Posted: 21 Dec 2010, 18:37
by Robbilie
but:
What if they are in different timezones?
Posted: 21 Dec 2010, 20:11
by dragagon
That is why you make sure all your times are in UTC by doing something like this in c#
Code: Select all
DateTime convertedDate = DateTime.SpecifyKind(
DateTime.Parse(dateStr),
DateTimeKind.Utc);
DateTime dt = converted.DateToLocalTime();
which will read in a datetime string as a UTC date time and will convert it to your local time. Either that or leave it always as UTC since you only care about short intervals.
The other option is to send a ping message, mark the current time on the system it was sent, then note the difference between when you sent it and when the pong response message was received. Then it doesn't matter what time the server says it is because its how long it took your client to get there and back again. and you could do this with any message as long as you limit it to the response.