Ping

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Post Reply
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Ping

Post 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
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post 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
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Hum ok. So its easy. Thanks ;-)
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany

Post by Robbilie »

but:

What if they are in different timezones?
dragagon
Posts: 19
Joined: 05 Dec 2010, 00:23

Post 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.
Post Reply