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

📄 idtimeudpserver.pas

📁 photo.163.com 相册下载器 多线程下载
💻 PAS
字号:
{ $HDR$}
{**********************************************************************}
{ Unit archived using Team Coherence                                   }
{ Team Coherence is Copyright 2002 by Quality Software Components      }
{                                                                      }
{ For further information / comments, visit our WEB site at            }
{ http://www.TeamCoherence.com                                         }
{**********************************************************************}
{}
{ $Log:  11795: IdTimeUDPServer.pas 
{
{   Rev 1.5    2004.02.03 5:44:36 PM  czhower
{ Name changes
}
{
{   Rev 1.4    1/21/2004 4:21:02 PM  JPMugaas
{ InitComponent
}
{
{   Rev 1.3    10/22/2003 08:48:06 PM  JPMugaas
{ Minor code cleanup.
}
{
{   Rev 1.1    2003.10.12 6:36:46 PM  czhower
{ Now compiles.
}
{
{   Rev 1.0    11/13/2002 08:03:28 AM  JPMugaas
}
unit IdTimeUDPServer;

interface

uses
  IdAssignedNumbers, IdGlobal, IdSocketHandle, IdUDPBase, IdUDPServer, Classes;

type
   TIdTimeUDPServer = class(TIdUDPServer)
   protected
     FBaseDate : TDateTime;
     procedure DoUDPRead(AData: TIdBytes; ABinding: TIdSocketHandle); override;
     procedure InitComponent; override;
   published
     property DefaultPort default IdPORT_TIME;
     {This property is used to set the Date the Time server bases it's   
     calculations from.  If both the server and client are based from the same
     date which is higher than the original date, you can extend it beyond the
     year 2035}
    property BaseDate : TDateTime read FBaseDate write FBaseDate;
   end;

implementation

uses
  IdGlobalProtocols, IdStack, SysUtils;

const
  {This indicates that the default date is Jan 1, 1900 which was specified
   by RFC 868.}
   TIMEUDP_DEFBASEDATE = 2;
{ TIdTimeUDPServer }

procedure TIdTimeUDPServer.InitComponent;
begin
  inherited;
  DefaultPort := IdPORT_TIME;
  {This indicates that the default date is Jan 1, 1900 which was specified
   by RFC 868.}
  FBaseDate := TIMEUDP_DEFBASEDATE;
end;

procedure TIdTimeUDPServer.DoUDPRead(AData: TIdBytes; ABinding: TIdSocketHandle);
var
   LTime : Cardinal;
begin
  inherited DoUDPRead(AData, ABinding);

  LTime := Trunc(extended(Now + TimeZoneBias - Int(FBaseDate)) * 24 * 60 * 60);
  LTime := GStack.HostToNetwork(LTime);
  SendBuffer(ABinding.PeerIP,ABinding.PeerPort, ToBytes(LTime));
end;

end.
 

⌨️ 快捷键说明

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