NMDayTim.pas
资源名称:FastNet.rar [点击查看]
上传用户:szzdds
上传日期:2013-09-18
资源大小:293k
文件大小:3k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit NMDayTim;
- {$X+}
- {$R-}
- {$IFDEF VER100}
- {$DEFINE NMF3}
- {$ENDIF}
- {$IFDEF VER110}
- {$DEFINE NMF3}
- {$ENDIF}
- {$IFDEF VER120}
- {$DEFINE NMF3}
- {$ENDIF}
- {$IFDEF VER125}
- {$DEFINE NMF3}
- {$ENDIF}
- interface
- uses
- SysUtils, Classes, Forms, Psock, Winsock, NMConst;
- {$IFDEF VER110}
- {$OBJEXPORTALL On}
- {$ENDIF}
- {$IFDEF VER120}
- {$OBJEXPORTALL On}
- {$ENDIF}
- {$IFDEF VER125}
- {$OBJEXPORTALL On}
- {$ENDIF}
- // CompName='TNMdayTim';
- // Major_Version='4';
- // Minor_Version='02';
- // Date_Version='012798';
- type
- TNMDayTime = class(TPowerSock)
- private
- function GetTimeStr: string;
- protected
- { Protected declarations }
- public
- constructor Create(AOwner: TComponent); override;
- property DayTimeStr: string read GetTimeStr;
- published
- end;
- implementation
- constructor TNMDayTime.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Port := 13;
- TimeOut := 500;
- end;
- function TNMDayTime.GetTimeStr: string;
- var i, ct: integer;
- handled: boolean;
- begin
- BeenCanceled := FALSE; {Turn Canceled off}
- if FConnected then {If already connected raise exception}
- raise ESockError.Create(sPSk_Cons_msg_Conn);
- ct := 0;
- repeat
- try
- ResolveRemoteHost; {Resolve the IP address of remote host}
- except
- on E: ESockError do
- if (E.Message = sPSk_Cons_msg_host_to) or (E.Message = sPSk_Cons_msg_host_Can) then raise;
- end;
- if RemoteAddress.sin_addr.S_addr = 0 then
- if ct > 0 then raise ESockError.Create(sPSk_Cons_msg_add_null) {If Resolving failed raise exception}
- else
- if not Assigned(OnInvalidHost) then raise ESockError.Create(sPSk_Cons_msg_add_null)
- else
- begin
- handled := FALSE;
- OnInvalidHost(handled);
- if not handled then raise ESockError.Create(sPSk_Cons_msg_add_null); {If Resolving failed raise exception}
- ct := ct + 1;
- end;
- until RemoteAddress.sin_addr.S_addr <> 0;
- StatusMessage(Status_Debug, sPSk_Cons_msg_Conning); {Inform Status}
- RemoteAddress.sin_family := AF_INET; {Make connected true}
- {$R-}
- if Proxy = '' then
- RemoteAddress.sin_port := htons(Port) {If no proxy get port from Port property}
- else
- RemoteAddress.sin_port := htons(ProxyPort); {else get port from ProxyPort property}
- {$R+}
- i := SizeOf(RemoteAddress); {i := size of remoteaddress structure}
- {Connect to remote host}
- succeed := FALSE;
- Timedout := FALSE;
- TimerOn;
- Winsock.Connect(ThisSocket, RemoteAddress, i);
- repeat
- application.processmessages; {Process messages till response received}
- until succeed or Timedout; {Responce received, Timed out or Cancelled exits loop}
- TimerOff;
- if Timedout then raise Exception.Create(Cons_Msg_ConnectionTimedOut);
- try
- while not DataAvailable do
- application.processmessages;
- Result := Read(0);
- finally
- Disconnect;
- end;
- end;
- end.