In terms of making an animated clock you essentially use a Timer and use scheduleRepeating(1000) to have it repeat every second. It's often easier to extend the Animation class, which uses a repeating Timer, and you can tell it to run every second. Just look at how the Animation class is used by some of the standard GWT Widgets.
In terms of synchronizing the server and client to be counting at the same time; this is much more difficult. I've never attempted to do this before. My first thought was for the server and client to agree on a future timestamp (say they communicate at time 12:23 then they might agree to start counting at 12:33 (10 seconds later) so that their communication will have long completed by then. The problem with this solution is that the likelihood of the server and client having both computer clocks synchronized is pretty slim. They are probably within 5 seconds of each other, however this is probably longer than the RPC communication. Let me think about this some more. Hopefully someone else will have a suggestion. Quite possibly the solution will be a different approach to the timing... such as not depending on the server at all for timing (even if you tell the server to store the times)... for example each client could be responsible for determining how long itself has been on it's turn and can tell the other clients how long it's been by communicating with the server. So other clients will be told how long it's been but the data they receive might be a couple seconds outdated, but that's ok, because when the client who's turn it is has run out of time it will prevent the user from making a move ON TIME and tell everyone else that it's turn has ended. So while other clients might not get the info immediately, the client who's turn it is won't ever get a couple extra seconds of time on his/her turn. On Feb 16, 10:41 am, Magnus <[email protected]> wrote: > Hi, > > my chess application needs time handling. > > As a general rule, all game related timing decisions are done on the > server. For example, when a move is made, the move's time is > determined and stored on the server. > > However, the client should have some visual feeling of a "running" > clock, i. e. a clock that is update every second. > > How can I realize this? I need help especially for these questions: > > - How do I realize the running clock? Do I have to a timer every > second, update the display and create a new timer? > > - As a starting point, the client receives some initial time value, e. > g. when a game is loaded, the client receives the information that > black has already spent 01:00 (1 hour). However, there is a little gap > due to the RPC processing time. First, the server sends back the > information "1 hour" to the client. Then, the client starts counting > "01:01", "01:02", and so on. However, when the client starts counting, > the time may already be at "01:03", depending on the bandwidth of the > internet connection. Can one do something about this? > > Thanks! > > Magnus -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
