SwissTime for Delphi Version 1.01
Copyright by Michael Gasser 1998
----------------------------------------------------------------------- 


Disclaimer of Warranty 

THIS SOFTWARE AND THE ACCOMPANYING FILES ARE SOLD "AS IS" AND 
WITHOUT WARRANTIES AS TO PERFORMANCE OR MERCHANTABILITY OR ANY 
OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. 

The user must assume the entire risk of using the program. 

ANY LIABILITY OF THE SELLER WILL BE LIMITED EXCLUSIVELY TO 
PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE. 
  
-----------------------------------------------------------------------   


  
The unit swisstime is used for getting the time from (daytime) timeservers as stated in RFC867 (TTime13, port 13, local
time), RFC868 ( TTime37, UTC) , RFC2030 ( SNTPClient , UTC, see the SNTP40.html document in this ZIP file ). 

Similar components for RFC867,RFC868 are distributed with C++Builder 3 and Delphi 4 (??), but there is no SNTPClient
(the best of the three ways to get the time from the internet) distributed with it! 

Before connecting to a timeserver, you have to set the HostAddr (for example bernina.ethz.ch), the
HostPort (if you don't use the default port) and the timeout property and at least, you have to handle the event 
OnDataAvailable : TDataAvailable. 

----------------------------------------------------------------------- 

Source code 
  

SwissTime.dcu is freeware. If you need the source code, you can get it by sending US$10 to 
Michael Gasser, Quellenweg 3, CH-3084 Wabern. 

Thank you very much. 
Delivery of the source code only by eMail. 

Contact : theiler.gasser@bluewin.ch 

----------------------------------------------------------------------- 

Example 
... 
... 
... 
with Time131 do 
begin 
        HostAddr := 'bernina.ethz.ch'; 
        Timeout   := 300;   
	// if you don't specify a port, the components default port will be set as HostPort. 

        connect; 
end; 
... 
... 
... 

procedure TForm1.Time131DataAvailable(Sender: TObject; Error: Word); 
begin 
        Showmessage( datetostr( time131.datetime) + ', '+ timetostr( time131.datetime) ); 
end; 
... 
... 

----------------------------------------------------------------------- 

The other events : 

property  OnWinsockError      		: TWinsockError 
(type  TWinsockError      		= procedure ( Sender: TObject; Error: word ) of object;) 

	Windows Socket Error. Error : Windows Socket Error code. 
  
  

property  OnTimeout                	: TNotifyEvent 
  

property  OnReceiveError       		: TNotifyEvent 
	The component did not receive the correct number of bytes. 
  

property  OnFormatError         	: TNotifyEvent 
	TTime13 component only : Unknown format. 
  

property  OnResolveError        	: TNotifyEvent 
	"Can't resolve host."  Host with address HostAddr does probably not exist. 
  
  
-----------------------------------------------------------------------  
  

TTime37 

type 
  TTime37 = class( TComponent ) 

  public 
      procedure Connect; 
      property  DateTime      : TDateTime        // DateTime sent by the server 
      property  AdjTime       : TDateTime        // Adjusted DateTime (AdjTime := DateTime + Ping/2) 
      property  Ping          : integer 
      property  LocalIP       : string 
      property  HostIP        : string 
      property  P37Msg        : Integer          // RFC868 message 
  

  published 
    { Published-Deklarationen } 

    property  HostAddr        : String 
    property  HostPort        : String 
    property  Timeout         : integer 

    property  OnWinsockError  : TWinsockError 
    property  OnDataAvailable : TDataAvailable 
    property  OnTimeout       : TNotifyEvent 
    property  OnReceiveError  : TNotifyEvent 
    property  OnResolveError  : TNotifyEvent 
  end; 

----------------------------------------------------------------------- 

TTime13 
  

type 
  TTime13 = class( TComponent ) 

  public 
    { Public-Deklarationen } 

      procedure Connect; 
      property  NormTimeStr   : String              // There is a problem, using RFC867. 
						    // The message from the time server
						    // (TimeStr) is not normed. 
                                                    // TTime13 norms the TimeStr received from the server. 
                                                    //  Format : YYYY/MM/DD,hh:mm:ss 
  
      property  TimeStr       : String              // Message received from the timeserver. 

      property  DateTime      : TDateTime           // Date and Time
      property  AdjTime       : TDateTime 	    // DateTime + Ping/2
      property  Ping          : integer 
      property  LocalIP       : string 
      property  HostIP        : string 
  

  published 
    { Published-Deklarationen } 

    property  HostAddr        : String 
    property  HostPort        : String 
    property  Timeout         : integer 

    property  OnWinsockError  : TWinsockError 
    property  OnDataAvailable : TDataAvailable 
    property  OnTimeout       : TNotifyEvent 
    property  OnReceiveError  : TNotifyEvent 
    property  OnFormatError   : TNotifyEvent 
    property  OnResolveError  : TNotifyEvent 
  end; 

----------------------------------------------------------------------- 


SNTPClient 

type Fourbytes = record 
      case integer of 
        0: ( b : array[1..4] of byte); 
        1: ( i : integer); 
      end; 
  

type NTP_Time  = record 
          seconds  : Fourbytes; 
          fraction : Fourbytes; 
     end; 
  

type SNTPMsgFormat = record 
       Info            : Fourbytes; 
       root_delay      : Fourbytes; 
       root_dispersion : Fourbytes; 
       reference_id    : Fourbytes; 

       ref_timestamp   : ntp_time; 
       orig_timestamp  : ntp_time; 
       rec_timestamp   : ntp_time; 
       trans_timestamp : ntp_time; 
     end; 

type  TSNTPError        = procedure (Sender: TObject; Error: word) of object; 
  

type 
  TSNTPClient = class(TComponent) 

  public 
    { Public-Deklarationen } 

    function    DisregardMsg( Mess : SNTPMsgFormat ) : boolean;  // see \Info\SNTP40.txt
    function    ntptimetodatetime ( t : ntp_time ) : TdateTime; 
  
    property    ServerIP       : string 
    property    LocalIP        : string 


    // Take a look at SNTP40.txt in the Info folder of this ZIP :
    property    Leapindicator  : integer        // see \Info\SNTP40.txt
    property    Version        : integer 	// see \Info\SNTP40.txt
    property    Mode           : integer 	// see \Info\SNTP40.txt
    property    Stratum        : integer 	// see \Info\SNTP40.txt
    property    Poll           : integer 	// see \Info\SNTP40.txt
    property    Precision      : integer 	// see \Info\SNTP40.txt
    property    Rootdelay      : double 	// see \Info\SNTP40.txt
    property    Rootdispersion : double 	// see \Info\SNTP40.txt
    property    Ref_time       : TDateTime 	// see \Info\SNTP40.txt
    property    Ori_time       : TDateTime 	// see \Info\SNTP40.txt
    property    Rec_time       : TDateTime 	// see \Info\SNTP40.txt
    property    Tra_time       : TDateTime 	// see \Info\SNTP40.txt

    property    Disregard      : boolean         // You should disregard the message received by the server.
    property    Ping           : integer 
    property    SNTPMsg        : SNTPMsgFormat   // Message from the server

    property    DateTime       : TDateTime 
    procedure   Connect; 
    property    LocalPort      : String 
    property    HostIP         : string 
    property    AdjTime        : TDateTime 	// AdjTime := DateiTime + Ping/2
  

  published 
    { Published-Deklarationen } 

    property    HostAddr       : String 
    property    HostPort       : String 
    property    Timeout        : integer 

    property    OnDataAvailable: TDataavailable 
    property    OnTimeout      : TNotifyEvent 
    property    OnWinsockError : TSNTPError 
    property    OnResolveError : TNotifyEvent 
    property    OnReceiveError : TNotifyEvent 
  end; 
  
----------------------------------------------------------------------- 
END OF THIS FILE  