Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Server time in applet

 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we get the server time in an applet?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. Just make an HTTP call to a server resource that replies with the time; you can use the HttpURLConnection class for this.
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,
Thanks for your reply............
I got the server date and implemented it successfully
Then I came across Devx Discussions where they said
the easiest way is to supply it with the local time on the webserver via an applet property in the HTML code.
You can then use that time as a base to calculate the difference between the local time on the users computer and the timeon your server....
But then you don't get the date time at that exact moment, we get the same date time when the applet was loaded everytime.
And then there's the overhead of calculating the difference between the local time.
I am able to implement both, just wanted to know which is the better way?
If the applet is calling the url many times for getting the server date, won't the performance be affected?
Thanks again............

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would the applet need to retrieve the server time "many times", however often "many" turns out to be? The server clock runs as fast as the client clock, so once the applet has an idea of the server time, it can take that into account.

But most applets consist largely of GUI code, and thus have lots of idle cycles during which the CPU is most likely underutilized. So an occasional network call should be fine.
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The applet is not used for any GUI operations, its just used for uploading files on the server from the client.
So, it needs to put time stamp for the uploaded files. So, if the client date and time is taken, the client system date has to be correct.
Hence, server time is needed. Taking the server time as parameter only once is also not acceptable, since the system date can be changed once the applet is loaded. So, I'm going ahead with calling the web page for the server time.
Thanks a lot for your help.........
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the file gets uploaded to the server anyway, wouldn't it be easier if the server assigned a timestamp right then and there?
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, that seems to be the right way..............but I'm not sure why its done this way.....
I am not complaining though, if I am learning something new........
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic