Daytime protocol and time protocol (1)

Source: Internet
Author: User
Tags printable characters domain server

This time, we will mainly explain the issues related to the daytime protocol and time protocol. Let's take a look at the content of the daytime protocol and time protocol. In a LAN, many systems require that each computer maintain time consistency. The WIN2000 system provides the time synchronization function with the master Domain Server, that is, the workstation only needs to log on to the master Domain Server, the time of the workstation system is automatically the same as that of the master Domain Server, but the next question is how to synchronize the master Domain Server with the world standard time. to get the world's standard time, it is more accurate to use the GPS satellite clock to get the standard time with millisecond-level precision, but this is for money. if we only need to connect to the Internet in seconds, we can use the standard time server on the Internet to get the standard time.

In fact, there are three different time services on the Internet, each of which is defined by Request for CommentRFC) as the Internet date and time standard. the three standards are: RFC-867, RFC-868 and RFC-1305. next we will first introduce RFC-867:

RFC867 Daytime Protocol (RFC867 Daytime Protocol)

This RFC standardizes an ARPA Internet community standard. All hosts on the ARPA Internet should adopt and implement this standard.

A useful measurement and debugging tool is the daytime protocol service. It is used to return the current time and date in the string format.

◆ TCP-based daytime Service

The daytime service is a TCP-based application. The server listens on TCP port 13. Once a connection is established, it returns the date and time in the ASCII format (any received data is ignored ), close the connection after the transfer.

◆ UDP-based daytime protocol service

The daytime service can also use UDP protocol, and its port is also 13. However, UDP uses datagram to transmit the current time. the received data is ignored.

◆ Daytime format

The daytime protocol does not have a specific format. We recommend that you use ASCII printable characters, space, and carriage return line breaks. daytime should be on one line.

The following are two popular formats:

A popular format is: Weekday, Month Day, Year Time-Zone

Example: Tuesday, February 22,198 2 17:37:43-PST

Another popular format is used in SMTP: dd mmm yy hh: mm: ss zzz

Example: 02 FEB 82 07:59:01 PST

Note: For machines, useful Time uses the Time Protocol RFC-868)

Next, we use the VB program to set the time of our computer system through RFC867 protocol. to simplify the program, the program does not perform date correction, but only performs time correction. add a Winsock Control to FORM1 and paste the following code to the FORM1 code form:

Option Explicit

Use RFC867 Daytime protocol to obtain standard time routines

Www.time.ac.cn is the National Time Service Center of the Chinese Emy of sciences, using Beijing Time

Time Format: Mon Jul 26 09:58:57 2004

Time.nist.gov is the American Institute of Standards and Technology, and adopts Gyeonggi time

 
 
  1. Time Format: 53212 04-07-26 02:00:12 50 0 0 488.3 UTC (NIST )*
  2. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  3. Dim NoSrv As Boolean
  4. Dim TimeFromNet
  5. Private Sub Form_Load ()
  6. Winsock1.Protocol = sckTCPProtocol 'adopts the TCP protocol
  7. NetTime "www.time.ac.cn" 'first takes the time of the Chinese Emy of Sciences National Time Service Center
  8. If NoSrv Or TimeFromNet = "" Then

If the time is not obtained from the Chinese Emy of Sciences National Time Service Center

 
 
  1. NetTime "time.nist.gov"  
  2. If NoSrv Or TimeFromNet = "" Then 

If you cannot get the time of the US standard Technology Institute, an error is reported.

 
 
  1. MsgBox "the network standard time server time.nist.gov is not detected! "
  2. Else

To reduce the network transmission error, take the time of the US standard technical institute for 2nd times.

 
 
  1. NetTime "time.nist.gov"
  2. If TimeFromNet = "" Then
  3. MsgBox "network standard time server time.nist.gov timeout! "
  4. Else
  5. TimeFromNet = Mid (TimeFromNet, 17, 8)
  6. TimeFromNet = TimeSerial (Hour (TimeFromNet) + 8) Mod 24, Minute (TimeFromNet), Second (TimeFromNet ))
  7. Time = timefromnet' set the system Time
  8. End If
  9. End If
  10. Else

In order to reduce the network transmission error, obtain the Time of the Chinese Emy of Sciences National Time Service Center for 2nd times.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.