Get internet time in delphi

I want to get the time and date from the Internet

I used the following code

IdDayTime1.ReadTimeout := 5000; IdDayTime1.Host := 'www.time.windows.com'; IdDayTime1.Port := 37 ; Label1.Caption := IdDayTime1.DayTimeStr; 

but i get: socket error # 11004

what is it and what did i do wrong

my internet and other things are fine

+4
source share
5 answers

DayTime is not an NTP protocol. DayTime uses port 13 rather than 37. 37 is used by the Time protocol, which, again, is not an NTP protocol that uses 123 (UDP). I don’t know if time.windows.com supports the DayTime and Time protocols, the most commonly used protocols for receiving time from a reliable time source is currently NTP and its simpler SNTP server, which replaced DayTime and Time protocols.

+7
source

Socket error 11004 means "bad address". You need to get rid of the www. Prefix, the correct adddress is time.windows.com.

+2
source

Here are some simple examples showing the use of idSNTP components

 var SNTPClient: TIdSNTP; begin SNTPClient := TIdSNTP.Create(nil); try SNTPClient.Host := 'pool.ntp.org'; SNTPClient.SyncTime; finally SNTPClient.Free; end; end; 
+1
source

If you use Time and Date, use the Indy IdSNTP component and set: host: time.windows.com

and in the Timer1Timer event (TTimer component) write:

 Label1.Caption := DateToStr(IdSNTP1.DateTime) + ' - ' + TimeToStr(IdSNTP1.DateTime); Label2.Caption := IdSNTP1.Host; 

you see by the form (labe1, label2) Date now AND Time now. Therefore, if you set Time synchronized, put IdSNTP1.SyncTime; in the Timer1Timer event.

+1
source

Try using Indy ntp client components with ntp pool.org servers. Works for me, if you have any problems, I will send an example code.

0
source

All Articles