473,573 Members | 4,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retreiving Server Time

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.bldr doc.gov", 13);
BufferedReader in = new BufferedReader
(new InputStreamRead er(s.getInputSt ream()));
boolean more = true;
while(more){
String line = in.readLine();
if(line == null)
more = false;
else
System.out.prin tln(line);
}}
catch(IOExeptio n 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
10 8211
Security problem.
"RadioFreq" <ra*******@eart hlink.net> wrote in message
news:PE******** **********@news read2.news.pas. earthlink.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.bldr doc.gov", 13);
BufferedReader in = new BufferedReader
(new InputStreamRead er(s.getInputSt ream()));
boolean more = true;
while(more){
String line = in.readLine();
if(line == null)
more = false;
else
System.out.prin tln(line);
}}
catch(IOExeptio n 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
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******** ***********@new s04.bloor.is.ne t.cable.rogers. com...
Security problem.
"RadioFreq" <ra*******@eart hlink.net> wrote in message
news:PE******** **********@news read2.news.pas. earthlink.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.bldr doc.gov", 13);
BufferedReader in = new BufferedReader
(new InputStreamRead er(s.getInputSt ream()));
boolean more = true;
while(more){
String line = in.readLine();
if(line == null)
more = false;
else
System.out.prin tln(line);
}}
catch(IOExeptio n 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
Check out java.sun.com for details on Java issues first:

http://java.sun.com/developer/techni...urity/applets/
"RadioFreq" <ra*******@eart hlink.net> wrote in message
news:cR******** **********@news read2.news.pas. earthlink.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******** ***********@new s04.bloor.is.ne t.cable.rogers. com...
Security problem.
"RadioFreq" <ra*******@eart hlink.net> wrote in message
news:PE******** **********@news read2.news.pas. earthlink.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.bldr doc.gov", 13);
BufferedReader in = new BufferedReader
(new InputStreamRead er(s.getInputSt ream()));
boolean more = true;
while(more){
String line = in.readLine();
if(line == null)
more = false;
else
System.out.prin tln(line);
}}
catch(IOExeptio n 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
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******** *********@twist er01.bloor.is.n et.cable.rogers .com...
Check out java.sun.com for details on Java issues first:

http://java.sun.com/developer/techni...urity/applets/
"RadioFreq" <ra*******@eart hlink.net> wrote in message
news:cR******** **********@news read2.news.pas. earthlink.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******** ***********@new s04.bloor.is.ne t.cable.rogers. com...
Security problem.
"RadioFreq" <ra*******@eart hlink.net> wrote in message
news:PE******** **********@news read2.news.pas. earthlink.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.bldr doc.gov",

13); > BufferedReader in = new BufferedReader
> (new InputStreamRead er(s.getInputSt ream()));
> boolean more = true;
> while(more){
> String line = in.readLine();
> if(line == null)
> more = false;
> else
> System.out.prin tln(line);
> }}
> catch(IOExeptio n 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
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******** *********@twist er01.bloor.is.n et.cable.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
Thanks 'NOS',

In my current applet I use the 'GregorianCalen dar' 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
GregorianCalend ar is using the client machine's time.

Thanks
John

"nos" <no*@nospam.com > wrote in message
news:LjoCb.3748 75$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
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*******@eart hlink.net> wrote in message
news:i5******** *******@newsrea d1.news.pas.ear thlink.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******** *********@twist er01.bloor.is.n et.cable.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
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
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******@spa m-I-am-not.twcny.rr.co m> wrote in message
news:u8******** *********@twist er.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5560
by: Guy Erez | last post by:
Hi, I'm running queries with MySql 4.0.17 that return thousands of records. Because I need to present them in GUI, I returieve the results in chunks using LIMIT, for example - get first 100, then the range 100-2000 and so on. The problem is as follows: in the first chunk, MySQL uses one strategy to fetch the results, and in the following...
2
1245
by: Reddy | last post by:
Hi, Once after inserting a record into a table is there a more efficient way of retreiving the id(autonumber field) value in the following example. Using a SQL server database. con.Open() strSql="insert into table1(column2) values('test1')" cmd = New OdbcCommand(strSql, con)
4
1564
by: James Pemberton | last post by:
I have recently created a ASP site utilizing Master Pages and all works fine until I want to proces my javascripts. Just to let you know, most of cliewnt side scripting is new to me. But anyway, I can retrieve and updat ethe value a textbox on the page by using the document.getElementById('Goals_Main_tbProduct0').value
8
1834
by: Jeff | last post by:
I asked this question sometime ago. some help was given, but A.) i didn't understand the help and B.) I can't find the post. i am looking for a way to take a table of stats on an HTML page, and turn the data into variables, and upload to a DB using ASP. say if a page contained stats from a golf tournament, i would be able to pull the data...
2
888
by: dave m | last post by:
Here's the scenerio: I have several (10 - 30) PCs that periodically need to get data (simple Y/N flag values) from a server in the same network. While all PCs run SQL Server, I don't want to use a Sql connection for this purpose. I was thinking about having the client PCs get the data from the server's registry via a Winform app. or a...
0
1117
by: yogeeswar | last post by:
HI ALL I AM USING DB2 8.1 AND I HAVE TWO TABLES PARENT TABLE 1)CODE IS PRIMARY KEY CODE CODE_DESC CATEGORY ----------- ---------------------------------------- ---------- ------------ 1 SelectByPlan A 2 SPT A ...
1
1857
by: yucefrizk | last post by:
hello all, I'm trying to write a code to retreive data from a database to an excel file, I achieved my code and everything is going good by running it through unix, but when I create a webpage to help users to extract data via internet I got an internal server error! anyone can help me??? thank you.. #!/usr/bin/perl
1
1943
by: i.sobha | last post by:
Hi, I tried retreiving an image from an access data base and display it to the asp page . The code is shown below. But the same is not working. Can someone provide me with some valuable inputs. Save the belo code in an asp ShowPicture.asp
6
1626
by: Igor | last post by:
Hi How can I reference a specific control in a web user form from web form's (page) code behind. In other words: I have a page (a web form) that has a web user form in it. I want to read a value in code behind of that page (web form) from a text box in the web user form. Kind regards
0
7741
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7661
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7977
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8165
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3692
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2163
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1256
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.