By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,737 Members | 1,971 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,737 IT Pros & Developers. It's quick & easy.

Retreiving Server Time

P: n/a
I am writing an applet to display Julian Day and Time on a webpage. I have
all the code written except for a class to open a socket and extract a
String with the time in it. I am getting the time from (NIST), a government
site.

The problem that I am running into is that it seems that I can extract the
time from the server as application, but when changing the code so that will
run as an applet it hangs up. Here is a sample of the application code:

import java.io.* ;
import java.net.* ;

public class SocketTest{
public static void main(String[] args){
try{
Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
BufferedReader in = new BufferedReader
(new InputStreamReader(s.getInputStream()));
boolean more = true;
while(more){
String line = in.readLine();
if(line == null)
more = false;
else
System.out.println(line);
}}
catch(IOExeption e) {}
}}

This works just fine, but when I try to change the app into an applet, it
does not work. Can someone offer their skills.

Thanks
John
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Security problem.
"RadioFreq" <ra*******@earthlink.net> wrote in message
news:PE******************@newsread2.news.pas.earth link.net...
I am writing an applet to display Julian Day and Time on a webpage. I have
all the code written except for a class to open a socket and extract a
String with the time in it. I am getting the time from (NIST), a government site.

The problem that I am running into is that it seems that I can extract the
time from the server as application, but when changing the code so that will run as an applet it hangs up. Here is a sample of the application code:

import java.io.* ;
import java.net.* ;

public class SocketTest{
public static void main(String[] args){
try{
Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
BufferedReader in = new BufferedReader
(new InputStreamReader(s.getInputStream()));
boolean more = true;
while(more){
String line = in.readLine();
if(line == null)
more = false;
else
System.out.println(line);
}}
catch(IOExeption e) {}
}}

This works just fine, but when I try to change the app into an applet, it
does not work. Can someone offer their skills.

Thanks
John

Jul 17 '05 #2

P: n/a
Thanks Thomas,

Security on my side or far side?
I do have a wireless network with a firewall, but I don't have any problems
with the application. Hmmm?

"Thomas A. Li" <tl*@corporola.com> wrote in message
news:ef*******************@news04.bloor.is.net.cab le.rogers.com...
Security problem.
"RadioFreq" <ra*******@earthlink.net> wrote in message
news:PE******************@newsread2.news.pas.earth link.net...
I am writing an applet to display Julian Day and Time on a webpage. I have all the code written except for a class to open a socket and extract a
String with the time in it. I am getting the time from (NIST), a

government
site.

The problem that I am running into is that it seems that I can extract the time from the server as application, but when changing the code so that

will
run as an applet it hangs up. Here is a sample of the application code:

import java.io.* ;
import java.net.* ;

public class SocketTest{
public static void main(String[] args){
try{
Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
BufferedReader in = new BufferedReader
(new InputStreamReader(s.getInputStream()));
boolean more = true;
while(more){
String line = in.readLine();
if(line == null)
more = false;
else
System.out.println(line);
}}
catch(IOExeption e) {}
}}

This works just fine, but when I try to change the app into an applet, it does not work. Can someone offer their skills.

Thanks
John


Jul 17 '05 #3

P: n/a
Check out java.sun.com for details on Java issues first:

http://java.sun.com/developer/techni...urity/applets/
"RadioFreq" <ra*******@earthlink.net> wrote in message
news:cR******************@newsread2.news.pas.earth link.net...
Thanks Thomas,

Security on my side or far side?
I do have a wireless network with a firewall, but I don't have any problems with the application. Hmmm?

"Thomas A. Li" <tl*@corporola.com> wrote in message
news:ef*******************@news04.bloor.is.net.cab le.rogers.com...
Security problem.
"RadioFreq" <ra*******@earthlink.net> wrote in message
news:PE******************@newsread2.news.pas.earth link.net...
I am writing an applet to display Julian Day and Time on a webpage. I have all the code written except for a class to open a socket and extract a
String with the time in it. I am getting the time from (NIST), a

government
site.

The problem that I am running into is that it seems that I can extract the time from the server as application, but when changing the code so that
will
run as an applet it hangs up. Here is a sample of the application
code:
import java.io.* ;
import java.net.* ;

public class SocketTest{
public static void main(String[] args){
try{
Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
BufferedReader in = new BufferedReader
(new InputStreamReader(s.getInputStream()));
boolean more = true;
while(more){
String line = in.readLine();
if(line == null)
more = false;
else
System.out.println(line);
}}
catch(IOExeption e) {}
}}

This works just fine, but when I try to change the app into an applet,

it does not work. Can someone offer their skills.

Thanks
John



Jul 17 '05 #4

P: n/a
nos
you probably don't need to know the time from NIST
because there is a good chance that your server is
synchronized with it via ntp so just use "date"
Besides if your server is synchronized, "date" will
probably give you a more accurate result than you
can do for yourself. Ntp sync takes care of packet
delay times.

"Thomas A. Li" <tl*@corporola.com> wrote in message
news:Sj*****************@twister01.bloor.is.net.ca ble.rogers.com...
Check out java.sun.com for details on Java issues first:

http://java.sun.com/developer/techni...urity/applets/
"RadioFreq" <ra*******@earthlink.net> wrote in message
news:cR******************@newsread2.news.pas.earth link.net...
Thanks Thomas,

Security on my side or far side?
I do have a wireless network with a firewall, but I don't have any

problems
with the application. Hmmm?

"Thomas A. Li" <tl*@corporola.com> wrote in message
news:ef*******************@news04.bloor.is.net.cab le.rogers.com...
Security problem.
"RadioFreq" <ra*******@earthlink.net> wrote in message
news:PE******************@newsread2.news.pas.earth link.net...
> I am writing an applet to display Julian Day and Time on a webpage. I
have
> all the code written except for a class to open a socket and extract
a > String with the time in it. I am getting the time from (NIST), a
government
> site.
>
> The problem that I am running into is that it seems that I can extract
the
> time from the server as application, but when changing the code so that will
> run as an applet it hangs up. Here is a sample of the application code: >
> import java.io.* ;
> import java.net.* ;
>
> public class SocketTest{
> public static void main(String[] args){
> try{
> Socket s = new Socket("time-A.timefreq.bldrdoc.gov",

13); > BufferedReader in = new BufferedReader
> (new InputStreamReader(s.getInputStream()));
> boolean more = true;
> while(more){
> String line = in.readLine();
> if(line == null)
> more = false;
> else
> System.out.println(line);
> }}
> catch(IOExeption e) {}
> }}
>
> This works just fine, but when I try to change the app into an

applet, it
> does not work. Can someone offer their skills.
>
> Thanks
> John
>
>



Jul 17 '05 #5

P: n/a
Thanks Thomas,

I now realize what is happening. An example of what I am doing is on my
webpage of astronomy-watch.com, where I can only extract the client machines
time. The problem with this is, to predict Satellite passes the user needs
to have the correct time +/- 2 seconds. Client machines can be off from
several minutes to hours if not properly maintained.

Obviously, this is done in a different way other than opening a socket. For
instance, looking at the time.gov/ site will display on the browser the real
time. Is this time seeded from the server side?

Thanks for your time, it's really appreciated!
John

"Thomas A. Li" <tl*@corporola.com> wrote in message
news:Sj*****************@twister01.bloor.is.net.ca ble.rogers.com...
Check out java.sun.com for details on Java issues first:

http://java.sun.com/developer/techni...urity/applets/

Jul 17 '05 #6

P: n/a
Thanks 'NOS',

In my current applet I use the 'GregorianCalendar' method to extract the
date/time information. If I use the 'Date' method am I extracting the server
machine's time or the client machine's time? I do know that
GregorianCalendar is using the client machine's time.

Thanks
John

"nos" <no*@nospam.com> wrote in message
news:LjoCb.374875$275.1216915@attbi_s53...
you probably don't need to know the time from NIST
because there is a good chance that your server is
synchronized with it via ntp so just use "date"
Besides if your server is synchronized, "date" will
probably give you a more accurate result than you
can do for yourself. Ntp sync takes care of packet
delay times.

Jul 17 '05 #7

P: n/a
nos
Ok so now I have to put on my thinking hat.
Date and calendar both get time from the client machine
which may or may not be synchronized to anything.
Windows XP synchronizes itself to nist, but only once
per week. Solaris comes
with ntp and it is most likely synchronized via the network.
But since you have no control over the client machine you have
to assume it is not synchronized.
Sorry to have mislead you but I am sort of stumped right now, maybe later
something will occur to me.

"RadioFreq" <ra*******@earthlink.net> wrote in message
news:i5***************@newsread1.news.pas.earthlin k.net...
Thanks Thomas,

I now realize what is happening. An example of what I am doing is on my
webpage of astronomy-watch.com, where I can only extract the client machines time. The problem with this is, to predict Satellite passes the user needs
to have the correct time +/- 2 seconds. Client machines can be off from
several minutes to hours if not properly maintained.

Obviously, this is done in a different way other than opening a socket. For instance, looking at the time.gov/ site will display on the browser the real time. Is this time seeded from the server side?

Thanks for your time, it's really appreciated!
John

"Thomas A. Li" <tl*@corporola.com> wrote in message
news:Sj*****************@twister01.bloor.is.net.ca ble.rogers.com...
Check out java.sun.com for details on Java issues first:

http://java.sun.com/developer/techni...urity/applets/


Jul 17 '05 #8

P: n/a
RadioFreq wrote:
I am writing an applet to display Julian Day and Time on a webpage. I have
all the code written except for a class to open a socket and extract a
String with the time in it. I am getting the time from (NIST), a government
site.

The problem that I am running into is that it seems that I can extract the
time from the server as application, but when changing the code so that will
run as an applet it hangs up.


As you have discovered in other threads, the issue is that the applet
sandbox will not let you talk to servers other that the one that the
applet is served from.

There are two common work-arounds:

1) Create a signed applet that requests permission to contact other
servers from the client.
2) Create some sort of server to run on the machine serving the applet
and have the applet get the time from that server. (There are many
options here: RMI, EJB, simple relay server, servlet, etc. Perhaps the
date service is already running on the server?)

Personally, assuming it is appropriate for your application, I would
consider re-writing the applet as a servlet or a JSP page.

Ray
Jul 17 '05 #9

P: n/a
Thanks Ray,

I am considering using a JSP as way to extract the time from the server and
produce the HTML with the time seeded from the server.

Thanks

"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:u8*****************@twister.nyroc.rr.com...
RadioFreq wrote:
I am writing an applet to display Julian Day and Time on a webpage. I have all the code written except for a class to open a socket and extract a
String with the time in it. I am getting the time from (NIST), a government site.

The problem that I am running into is that it seems that I can extract the time from the server as application, but when changing the code so that will run as an applet it hangs up.


As you have discovered in other threads, the issue is that the applet
sandbox will not let you talk to servers other that the one that the
applet is served from.

There are two common work-arounds:

1) Create a signed applet that requests permission to contact other
servers from the client.
2) Create some sort of server to run on the machine serving the applet
and have the applet get the time from that server. (There are many
options here: RMI, EJB, simple relay server, servlet, etc. Perhaps the
date service is already running on the server?)

Personally, assuming it is appropriate for your application, I would
consider re-writing the applet as a servlet or a JSP page.

Ray

Jul 17 '05 #10

P: n/a
I think I have a solution.
I will use a JSP servlet to retrieve the server time, then seed this server
time to the applet.
I don't know why I didn't think about this before. Sometimes I just have to
sit back and look at my problem from different angle.
At least, you answered my question as to why I couldn't open a socket with
an applet. I'll let everyone know how this turns out.

Thanks for all you help.
Free the Code - OpenSource!
John

"nos" <no*@nospam.com> wrote in message
news:dhsCb.377197$ao4.1258920@attbi_s51...
Ok so now I have to put on my thinking hat.
Date and calendar both get time from the client machine
which may or may not be synchronized to anything.
Windows XP synchronizes itself to nist, but only once
per week. Solaris comes
with ntp and it is most likely synchronized via the network.
But since you have no control over the client machine you have
to assume it is not synchronized.
Sorry to have mislead you but I am sort of stumped right now, maybe later
something will occur to me.

"RadioFreq" <ra*******@earthlink.net> wrote in message
news:i5***************@newsread1.news.pas.earthlin k.net...
Thanks Thomas,

I now realize what is happening. An example of what I am doing is on my
webpage of astronomy-watch.com, where I can only extract the client

machines
time. The problem with this is, to predict Satellite passes the user needs to have the correct time +/- 2 seconds. Client machines can be off from
several minutes to hours if not properly maintained.

Obviously, this is done in a different way other than opening a socket.

For
instance, looking at the time.gov/ site will display on the browser the

real
time. Is this time seeded from the server side?

Thanks for your time, it's really appreciated!
John

"Thomas A. Li" <tl*@corporola.com> wrote in message
news:Sj*****************@twister01.bloor.is.net.ca ble.rogers.com...
Check out java.sun.com for details on Java issues first:

http://java.sun.com/developer/techni...urity/applets/



Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.