Need server timer

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

Madhav
Posts: 78
Joined: 27 Nov 2012, 04:41

Need server timer

Postby Madhav » 30 May 2013, 05:03

I need to show a clock to the users while getting the time from the server.
So that the users from different part of the world can have a common clock depending on which they can meet at some locations.

The clock needs to be running all the time and whenever the client-user logs in, the time should be displayed on clock icon.

How to get time from server?
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Need server timer

Postby Bax » 30 May 2013, 07:08

In the server login response you could send the server time, and then create a timer on the client which updates it each second.
Paolo Bax
The SmartFoxServer Team
Madhav
Posts: 78
Joined: 27 Nov 2012, 04:41

Re: Need server timer

Postby Madhav » 30 May 2013, 12:18

Thanx for reply Bax,

Please elaborate, How exactly do I get server time? (only server uptime is there)!!!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Need server timer

Postby Lapo » 30 May 2013, 12:44

Server time is not much related to the SmartFoxServer API.
It's just a matter of getting the time using the Java standard library (aka JDK)

Take a look here for example:
http://www.tutorialspoint.com/java/java_date_time.htm
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC
Contact:

Re: Need server timer

Postby Carl Lydon » 26 Jun 2015, 22:10

In the old SFS1X extensions it was very easy to get the server time.

I think the SFS2X method is something like this:


Code: Select all

package com.xxx.myProject.requestHandlers;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import java.util.Date;

public class JoinBotRoomRequestHandler extends BaseClientRequestHandler
{
   @Override
   public void handleClientRequest(User user, ISFSObject params) {
      Date date = new Date();
       trace(date.toString());
   }
}
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Need server timer

Postby Lapo » 27 Jun 2015, 11:30

Java has several ways to deal with date/time.
See here:
http://www.mkyong.com/java/java-how-to- ... -calender/

and here too:
http://stackoverflow.com/questions/5175 ... me-in-java

The "Joda" library referenced in the articles is also provided with SFS2X, so you can use that as well, especially if you need to execute time-based calculations.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 23 guests