⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csntp.htm

📁 简单网络时间协议实现的源代码
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html>

<head>
<title>CSNTPClient v1.07</title>
</head>

<body bgcolor="#FFFFFF">

<p align="left"><img src="csntp.gif" width="32" height="32" alt="csntp.gif (362 bytes)"><font
face="Arial"><strong><big><big><big><big>CSNTPClient v1.07</big></big></big></big></strong></font></p>

<p><font face="Arial">Welcome to <strong>CSNTPClient</strong>, a collection of freeware
MFC classes to encapsulate the SNTP protocol. </font></p>

<p>&nbsp;</p>

<table>
  <tr>
    <td><font face="Arial"><a href="#Features">Features</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Usage">Usage</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Copyright">Copyright</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#History">History</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#APIReference">API Reference</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Enhancements">Planned Enhancements</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Contact">Contacting the Author</a></font></td>
  </tr>
</table>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><font face="Arial"><a name="Features"></a><big><strong><big>Features</big></strong></big>
</font>

<ul>
  <li><font color="#000000" size="3" face="Arial">Simple and clean C++ interface.</font></li>
  <li><font color="#000000" size="3" face="Arial">The interface provided is synchronous which
    provides an easier programming model than using asynchronous sockets.</font></li>
  <li><font color="#000000" size="3" face="Arial">Raw sockets are used instead of MFC sockets.
    This means that the code will work in a console application without any problems</font></li>
  <li><font color="#000000" size="3" face="Arial">A configurable timeout for the connection
    can be set through the class API.</font></li>
  <li><font color="#000000" size="3" face="Arial">The classes are fully Unicode compliant and
    include Unicode built options in the workspace file.</font></li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><font face="Arial"><a name="Usage"></a><big><big><strong>Usage</strong></big></big> </font>

<ul>
  <li><font face="Arial">You need to download the CWSocket classes separately 
  from my web site at <a href="http://www.naughter.com/w3mfc.html">
  http://www.naughter.com/w3mfc.html</a> as this module is not provided in the 
  download. Then copy in the the SocMFC.h &amp; SocMFC.cpp into your CSNTPClient's 
  source code directory.</font></li>
  <li><font color="#000000" size="3" face="Arial">To use the class in your code simply include
    sntp.cpp and SocMFC.cpp in your project and #include sntp.h in which ever of your modules needs to make
    calls to the SNTP class. </font></li>
  <li><font face="Arial">Your code will need to include MFC either statically or dynamically.</font></li>
  <li><font face="Arial">You will need to have a functioning winsock stack installed 
  and initialized (via AfxSocketInit or WSAStartup).</font></li>
  <li><font face="Arial">You will also need to have winsock.h or afxsock.h and afxpriv.h 
  in your precompiled header.</font></li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><b><font face="Arial" size="5"><a name="Copyright"></a>Copyright</font></b></p>
<ul>
  <li><font face="Arial" size="3">You are allowed to include the source code in
    any product (commercial, shareware, freeware or otherwise) when your product
    is released in binary form.</font></li>
  <li><font face="Arial" size="3">You are allowed to modify the source code in
    any way you want except you cannot modify the copyright details at the top
    of each module.</font></li>
  <li><font face="Arial" size="3">If you want to distribute source code with
    your application, then you are only allowed to distribute versions released
    by the author. This is to maintain a single distribution point for the
    source code.</font></li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><font face="Arial"><big><a name="History"></a></big><font color="#000000" size="5"><strong>History</strong></font></font></p>

<p><font face="Arial"><font color="#000000" size="3"><strong>V1.0 (8 August 1998)</strong></font>
</font>

<ul>
  <li><font face="Arial"><font size="3"><font color="#000000">Initial public release.</font></font><big>
    </big></font></li>
</ul>

<p><strong><font color="#000000" size="3" face="Arial">V1.01 (1</font><font face="Arial"><font
size="3"><font color="#000000">6</font></font><font color="#000000" size="3"> </font></font><font
face="Arial" color="#000000" size="3">November 1998)</font></strong><font face="Arial"> </font>

<ul>
  <li><font face="Arial">m_nOriginateTime was getting set incorrectly in the SNTP response.
    Has now been fixed.</font></li>
  <li><font face="Arial">GetLastError now works when a timeout occurs.</font></li>
</ul>

<p><strong><font color="#000000" size="3" face="Arial">V1.02 (25 June 2000)</font></strong>
<ul>
  <li><font face="Arial">Fixed an issue where the packing order of the NtpBasicInfo
    struct was causing problems. Now packing is set to 1 byte for this struct.</font></li>
</ul>

<p><strong><font color="#000000" size="3" face="Arial">V1.03 (23 July 2000)</font></strong>
<ul>
  <li><font face="Arial">Added Windows CE 2.11 compatibility. Thanks to Andre Rippstein
    for the work.</font></li>
</ul>

<p><strong><font color="#000000" size="3" face="Arial">V1.04 (29 March 2001)</font></strong>
<ul>
  <li><font face="Arial"> Updated copyright message</font></li>
  <li><font face="Arial">Fixed a handle leak RevertSetTimePriviledge where the process
    token was not been closed</font></li>
</ul>

<p><strong><font color="#000000" size="3" face="Arial">V1.05 (25 August 2002)</font></strong>
<ul>
  <li><font face="Arial">Updated sample app to work correctly for the Unicode
    configurations</font></li>
  <li><font face="Arial">Sample app now uses CWinApp instance in sample app</font></li>
  <li><font face="Arial">Sample app now uses MFC support for initializing
    Winsock stack</font></li>
  <li><font face="Arial">Sample app now uses MFC support for parsing its command
    line.</font></li>
</ul>

<p><strong><font color="#000000" size="3" face="Arial">V1.06 (13 March 2003)</font></strong>
<ul>
  <li><font face="Arial">Fixed a bug in CNtpSocket::IsReadible in the setup of 
  the timeval structure. Thanks to &quot;InBloom Support&quot; for reporting this.</font></li>
</ul>

<p><strong><font color="#000000" size="3" face="Arial">V1.07 (21 September 2003)</font></strong>
<ul>
  <li><font face="Arial">Class now uses CWSocket class (which you will need to 
  download separately) to provide sockets 
  capability. This now allows the class to support connecting via a Socks 5 
  proxy.</font></li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p class="crt"><font face="Arial"><a name="APIReference"></a><big><big><strong>API
Reference</strong></big></big></font></p>

<p><font face="Arial">The API consists of the  classes:</font></p>

<p>&nbsp;</p>

<p><strong><font face="Arial">CNtpTime</font></strong></p>

<p><font face="Arial">This is an encapsulation of a time instance as used in the SNTP
protocol. This consists of a 64 bit unsigned integer with the top 32 bits containing the
number of seconds since 1st January 1900 and the lower 32 bits contain the fraction of
seconds.</font></p>

<p>&nbsp;</p>

<p><strong><font face="Arial"><a href="#CNtpTime">CNtpTime</a><br>
<a href="#operator=">operator=</a><br>
<a href="#operator-">operator-</a><br>
<a href="#operator+">operator+</a><br>
<a href="#operator SYSTEMTIME">operator SYSTEMTIME</a><br>
<a href="#operator CNtpTimePacket">operator CNtpTimePacket</a><br>
<a href="#operator unsigned __int64">operator unsigned __int64</a><br>
<a href="#Seconds">Seconds</a><br>
<a href="#Fraction">Fraction</a><br>
<a href="#GetCurrentTime">GetCurrentTime</a><br>
<a href="#MsToNtpFraction">MsToNtpFraction</a><br>
<a href="#NtpFractionToMs">NtpFractionToMs</a><br>
<a href="#NtpFractionToSecond">NtpFractionToSecond</a></font></strong></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><strong><font face="Arial">NtpServerResponse</font></strong></p>

<p><font face="Arial">This is a simple encapsulation of the information retrieved from the
SNTP server. It contains:</font></p>

<p>&nbsp;</p>

<p><font face="Arial"><strong><a href="#m_nLeapIndicator">m_nLeapIndicator<br>
</a><a href="#m_nStratum">m_nStratum</a><br>
<a href="#m_nOriginateTime">m_OriginateTime</a><br>
<a href="#m_ReceiveTime">m_ReceiveTime</a><br>
<a href="#m_TransmitTime">m_TransmitTime</a><br>
<a href="#m_DestinationTime">m_DestinationTime</a><br>
<a href="#m_RoundTripDelay">m_RoundTripDelay</a><br>
<a href="#m_LocalClockOffset">m_LocalClockOffset</a><br>
</strong></font></p>

<p>&nbsp;</p>

<p><strong><font face="Arial">CSNTPClient</font></strong></p>

<p><font face="Arial">The actual class to call to perform a time lookup is CSNTPClient and
it consists of:</font></p>

<p>&nbsp;</p>

<p><font face="Arial"><strong><a href="#CSNTPClient">CSNTPClient<br>
</a><a href="#GetServerTime">GetServerTime</a><br>
<a href="#GetTimeout">GetTimeout</a><br>
<a href="#SetTimeout">SetTimeout</a><br>
<a href="#SetClientTime">SetClientTime</a><br>
</strong></font></p>

<p>&nbsp;</p>

<p><a name="CNtpTime"></a><font face="Arial"><big><strong>CNtpTime::CNtpTime</strong></big></font></p>

<p><font face="Arial"><strong>CNtpTime();<br>
CNtpTime(const CNtpTime&amp; </strong><em>time</em><strong>);<br>
CNtpTime(CNtpTimePacket&amp; </strong><em>packet</em><strong>);<br>
CNtpTime(const SYSTEMTIME&amp; </strong><em>st</em><strong>);</strong></font></p>

<p><font face="Arial"><strong>Parameters</strong></font></p>

<p><font face="Arial"><em>time</em> Another CNtpTime instance.</font></p>

<p><font face="Arial"><em>packet</em> An CNtpTimePacket instance. This is a simple struct
representing the data as sent over the wire.</font></p>

<p><font face="Arial"><em>st</em> A Win32 SDK SYSTEMTIME instance.</font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">Standard C++ constructor.</font></p>

<p>&nbsp;</p>

<p><a name="operator="></a><font face="Arial"><big><strong>CNtpTime::operator=</strong></big></font></p>

<p><strong><font face="Arial">CNtpTime&amp; operator=(const CNtpTime&amp; time);</font></strong></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">Standard operator= for the class.</font></p>

<p>&nbsp;</p>

<p><a name="operator-"></a><big><strong><font face="Arial">CNtpTime::operator-</font></strong></big></p>

<p><font face="Arial"><strong>double operator-(const CNtpTime&amp; </strong><em>time</em><strong>)
const;</strong></font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">Standard operator- for the class.</font></p>

<p>&nbsp;</p>

<p><a name="operator+"></a><strong><font face="Arial">CNtpTime::operator+</font></strong></p>

<p><font face="Arial"><strong>CNtpTime operator+(const double&amp; </strong><em>timespan</em><strong>)
const;</strong></font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">Standard operator+ for the class.</font></p>

<p>&nbsp;</p>

<p><a name="operator SYSTEMTIME"></a><big><strong><font face="Arial">CNtpTime::operator
SYSTEMTIME</font></strong></big></p>

<p><strong><font face="Arial">operator SYSTEMTIME() const;</font></strong></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">operator method which returns a SDK SYSTEMTIME representation of the
Ntp time.</font></p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -