IP*Works!

ipworks
Class Netclock

java.lang.Object
  |
  +--ipworks.Netclock

public class Netclock
extends java.lang.Object

The NetClock control provides the current (GMT) time from an Internet Time Server.

The address of the Time Server is provided in the TimeServer property. You get the time by calling the GetTime method or setting the Action property to netclockGetTime .

The control also allows you to synchronize your system time with that of the TimeServer . This is done through the GetAndSetTime method or the Action property. Setting Action to netclockGetAndSetTime will request the time from the server and then set the system clock to match it.


Field Summary
static int netclockGetAndSetTime
           
static int netclockGetTime
           
static int netclockIdle
           
 
Constructor Summary
Netclock()
           
 
Method Summary
 void addNetclockEventListener(NetclockEventListener l)
           
 void fireError(int errorCode, java.lang.String description)
          Information about errors during data delivery.
 int getAction()
          An action code for the control.
 void getAndSetTime()
          Same as the netclockGetTime action, but system clock is also set to the received time.
 java.lang.String getLocalHost()
          The name of the local host or user-assigned IP interface through which connections are initiated or accepted.
 java.lang.String getLocalTime()
          The time returned by the TimeServer converted to local time.
 java.lang.String getServerTime()
          The time returned by the TimeServer .
 void getTime()
          Sends a time request to the TimeServer to ge the current time.
 int getTimeout()
          A timeout for the component.
 int getTimePort()
          The UDP port where the remote Time server is listening.
 java.lang.String getTimeServer()
          The time server to request the time from.
 void removeNetclockEventListener(NetclockEventListener l)
           
 void setAction(int action)
          An action code for the control.
 void setLocalHost(java.lang.String localHost)
          The name of the local host or user-assigned IP interface through which connections are initiated or accepted.
 void setTimeout(int timeout)
          A timeout for the component.
 void setTimePort(int timePort)
          The UDP port where the remote Time server is listening.
 void setTimeServer(java.lang.String timeServer)
          The time server to request the time from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

netclockIdle

public static final int netclockIdle

netclockGetTime

public static final int netclockGetTime

netclockGetAndSetTime

public static final int netclockGetAndSetTime
Constructor Detail

Netclock

public Netclock()
Method Detail

getAction

public int getAction()
An action code for the control. The following are possible values for the Action property and the corresponding descriptions:
netclockIdle (0)
Default action. It can also be used to interupt the current operation.
netclockGetTime (1)
Sends a time request to the TimeServer on port 37. The reply is provided in the ServerTime property.
netclockGetAndSetTime(2)
Same as the netclockGetTime action, but the system clock is also set to the received time (adjusted for timezone differences).

After a successful time request has completed, the control returns to netclockIdle .


setAction

public void setAction(int action)
               throws IPWorksException
An action code for the control. The following are possible values for the Action property and the corresponding descriptions:
netclockIdle (0)
Default action. It can also be used to interupt the current operation.
netclockGetTime (1)
Sends a time request to the TimeServer on port 37. The reply is provided in the ServerTime property.
netclockGetAndSetTime(2)
Same as the netclockGetTime action, but the system clock is also set to the received time (adjusted for timezone differences).

After a successful time request has completed, the control returns to netclockIdle .


getLocalHost

public java.lang.String getLocalHost()
The name of the local host or user-assigned IP interface through which connections are initiated or accepted. The LocalHost property contains the name of the local host as obtained by the gethostname() Winsock call, or if the user has assigned an IP address, the value of that address.

In multihomed hosts (machines with more than one IP interface) setting LocalHost to the value of an interface will make the control initiate connections (or accept in the case of server controls) only through that interface.

If the control is connected, the LocalHost property shows the IP address of the interface through which the connection is made in internet dotted format (aaa.bbb.ccc.ddd). In most cases, this is the address of the local host, except for multihomed hosts (machines with more than one IP interface).

NOTE: LocalHost is not persistent. You must always set it in code, and never in the property window.


setLocalHost

public void setLocalHost(java.lang.String localHost)
                  throws IPWorksException
The name of the local host or user-assigned IP interface through which connections are initiated or accepted. The LocalHost property contains the name of the local host as obtained by the gethostname() Winsock call, or if the user has assigned an IP address, the value of that address.

In multihomed hosts (machines with more than one IP interface) setting LocalHost to the value of an interface will make the control initiate connections (or accept in the case of server controls) only through that interface.

If the control is connected, the LocalHost property shows the IP address of the interface through which the connection is made in internet dotted format (aaa.bbb.ccc.ddd). In most cases, this is the address of the local host, except for multihomed hosts (machines with more than one IP interface).

NOTE: LocalHost is not persistent. You must always set it in code, and never in the property window.


getLocalTime

public java.lang.String getLocalTime()
The time returned by the TimeServer converted to local time. The server provides Greenwich Mean Time (GMT). This property contains the corresponding local time formatted as "MM/DD/YYYY HH:MM:SS" (where "HH" is in 24 hour format).


getServerTime

public java.lang.String getServerTime()
The time returned by the TimeServer . The time is Greenwich Mean Time (GMT) formatted as "MM/DD/YYYY HH:MM:SS GMT" (where "HH" is in 24 hour format).

For the corresponding local time, please consult the LocalTime property.


getTimeout

public int getTimeout()
A timeout for the component. If Timeout is set to a positive value, and an operation cannot be completed immediately, the control will retry the operation for a maximum of Timeout seconds.

The default value for Timeout is 10 (seconds).


setTimeout

public void setTimeout(int timeout)
                throws IPWorksException
A timeout for the component. If Timeout is set to a positive value, and an operation cannot be completed immediately, the control will retry the operation for a maximum of Timeout seconds.

The default value for Timeout is 10 (seconds).


getTimePort

public int getTimePort()
The UDP port where the remote Time server is listening. The TimePort is the UDP port on the TimeServer where to send Time requests to.


setTimePort

public void setTimePort(int timePort)
                 throws IPWorksException
The UDP port where the remote Time server is listening. The TimePort is the UDP port on the TimeServer where to send Time requests to.


getTimeServer

public java.lang.String getTimeServer()
The time server to request the time from. This property should be set to a valid internet address of a time server (default is "128.118.25.3", or "clock.psu.edu"). The server will reply with its current time (GMT).

Time request are sent to port TimePort (default 37) on the TimeServer .


setTimeServer

public void setTimeServer(java.lang.String timeServer)
                   throws IPWorksException
The time server to request the time from. This property should be set to a valid internet address of a time server (default is "128.118.25.3", or "clock.psu.edu"). The server will reply with its current time (GMT).

Time request are sent to port TimePort (default 37) on the TimeServer .


fireError

public void fireError(int errorCode,
                      java.lang.String description)
Information about errors during data delivery. (Called internally to dispatch the event.)
See Also:
NetclockErrorEvent

getAndSetTime

public void getAndSetTime()
                   throws IPWorksException
Same as the netclockGetTime action, but system clock is also set to the received time. Same as the netclockGetTime action, but the system clock is also set to the received time (adjusted for timezone differences).

Calling this method is equivalent to setting the Action property to netclockGetAndSetTime .


getTime

public void getTime()
             throws IPWorksException
Sends a time request to the TimeServer to ge the current time. Sends a time request to the TimeServer on port 37. The reply is provided in the ServerTime property, and the equivalent local time is provided in the LocalTime property.

Calling this method is equivalent to setting the Action property to netclockGetTime .


addNetclockEventListener

public void addNetclockEventListener(NetclockEventListener l)
                              throws java.util.TooManyListenersException

removeNetclockEventListener

public void removeNetclockEventListener(NetclockEventListener l)

IP*Works!

Copyright (c) 2001 /n software inc. - All rights reserved.