There are two links to the source code further up in this message thread.
yes, I download it. But, as Stefan wrote, the source code of the function GetSntp() is not present.
Stefan Haupt wrote on 26 Nov 2012 09:29
I found parts of the source here
http://www4.zzz.com.tw/phpbb2/viewtopic.php?t=29
But the function GetSntp() is missing, maybe you can contact the author
and Jeff Barnes wrote on 26 Nov 2012 20:23
I was able to get it working by linking the .lib file then adding an INCLUDE "TSNTP.PRG"
The sorce of Jeff with the sntp.lib, work with any ntp server, but over the 32 requests always returns "fail"
This is my last test with the change, every test, of the ntp server:
(is the same if the time between 2 requests is 1 sec. or 5 min. o also 30 min.)
(is the same if renew the object oSntp)
- Code: Select all Expand view RUN
- Func TestNTP()
Local aNet := {},;
nPort := 123,;
cIp := "ntp1.inrim.it",; // "time.windows.com",;
lSync := .F.,;
oSntp := NIL,;
cTimeTest := "",;
nX,;
lOk := .F.,;
cServer
cIp := { "1.it.pool.ntp.org", ;
"ntp1.inrim.it" ,;
"time.windows.com",;
"ntp2.inrim.it" ,;
"1.europe.pool.ntp.org" }
? "test begin"
// test-1
// lSync = .T., ?????, ? LocalTime ? NTP Server ????
// or oSntp := TSntp():New(); oSntp:cIp := '....'; oSntp:nPort = ....
IF ValType( cIp ) == "A"
cServer := cIp[1]
FOR nX := 0 TO 200
Millisec( 1000 * 1 ) // 60 *
// is the same if the time between 2 requests is 1 sec. or 5 min. o also 30 min.
cServer := cIp[ Val( cValToChar( nX % Len( cIp ) + 1 ) ) ]
IF nX % 30 == 0
// is the same if renew the object oSntp
oSntp := Nil
SysRefresh()
oSntp := TSntp():New( cServer, nPort, lSync )
ENDIF
If oSntp:GetData( @cServer )
MyLogFile( "tst.log", { oSntp:DateTime2(), cServer } )
Else
MyLogFile( "tst.log", { "FAIL", cServer, oSntp:nError } )
ENDIF
NEXT
ELSE
cServer := cIp
oSntp := TSntp():New( cServer, nPort, lSync )
FOR nX := 1 TO 200
Millisec( 1000 * 5 ) // 60 *
If oSntp:GetData( @cServer )
MyLogFile( "tst.log", { oSntp:DateTime2(), cServer } )
Else
MyLogFile( "tst.log", { "FAIL", cServer, oSntp:nError } )
ENDIF
NEXT
ENDIF
Return NIL
// TSNTP.PRG
// Copyright by WenSheng come from TAIWAN
#include "hbclass.ch"
#include "common.ch"
CLASS TSNTP
DATA cServer,; // server name/ip
nPort,; // server port
lSync,; // Sync flag
lError
DATA nYear,;
nMonth,;
nDay,;
nWeek,;
nDayOfYear
DATA nHours,;
nMinute,;
nSeconds,;
nError
METHOD New( cServer, nPort, lSync)
METHOD GetData()
MESSAGE DATE METHOD _Date()
MESSAGE TIME METHOD _Time()
MESSAGE DATETIME METHOD _DateTime()
MESSAGE DATETIME2 METHOD _DateTime2()
ENDCLASS
//
METHOD New( cServer, nPort, lSync ) CLASS TSNTP
DEFAULT cServer to "time.windows.com" // ????
DEFAULT nPort to 123 // ?? port
DEFAULT lSync to .F. // ????
::cServer := cServer
::nPort := nPort
::lSync := lSync
::lError := .F.
::nError := 0
RETURN Self
//
METHOD GetData( cServer ) CLASS TSNTP
Local xRet
DEFAULT cServer := ::cServer
xRet := GetSNTP( cServer, ::nPort, ::lSync )
If ValType(xRet) == "N"
::lError := .T.
::nError := xRet
::nYear := 0
::nMonth := 0
::nDay := 0
::nHours := 0
::nMinute := 0
::nSeconds := 0
::nWeek := 0
::nDayOfYear := 0
Else
::lError := .F.
::nError := 0
// 0 1 2
// 12345678901234567890
// ???? yyyymmddhhmmsswyda
// ? "|" + xRet + "|"
::nYear := Val( Substr( xRet, 1, 4 ))
::nMonth := Val( Substr( xRet, 5, 2 ))
::nDay := Val( Substr( xRet, 7, 2 ))
::nHours := Val( Substr( xRet, 9, 2 ))
::nMinute := Val( Substr( xRet, 11, 2 ))
::nSeconds := Val( Substr( xRet, 13, 2 ))
::nWeek := Val( Substr( xRet, 15, 1 ))
::nDayOfYear := Val( Substr( xRet, 16, 3 ))
EndIf
RETURN ! ::lError
//
METHOD _Date() CLASS TSNTP
RETURN StoD( PadL( ::nYear, 4, "0" )+;
PadL( ::nMonth, 2, "0" )+;
PadL( ::nDay, 2, "0" ))
//
METHOD _Time() CLASS TSNTP
RETURN PadL( ::nHours, 2, "0" )+":"+;
PadL( ::nMinute, 2, "0" )+":"+;
PadL( ::nSeconds, 2, "0" )
METHOD _DateTime()
RETURN PadL( ::nYear, 4, "0" ) + ;
PadL( ::nMonth, 2, "0" ) + ;
PadL( ::nDay, 2, "0" ) + ;
PadL( ::nHours, 2, "0" ) + ;
PadL( ::nMinute, 2, "0" ) + ;
PadL( ::nSeconds, 2, "0" )
METHOD _DateTime2()
RETURN PadL( ::nMonth, 2, "0" ) + "/" + ;
PadL( ::nDay, 2, "0" ) + "/" +;
PadL( ::nYear, 4, "0" ) + " " + ;
PadL( ::nHours, 2, "0" ) + ":" +;
PadL( ::nMinute, 2, "0" ) + ":" +;
PadL( ::nSeconds, 2, "0" )
I can not see errors for this limit and i think that probably the snpt.lib in tsntp.rar contain the GetSntp() linkable to the xharbour object but it is created with the limit, for this reason I search the source code of sntp.lib
As Stefan wrote: "maybe you can contact the author" does anyone know the author? his email address?
Thanks in advance.