用ICS控件做ASP DNS组件时出现的问题(100分)

  • 主题发起人 主题发起人 cddyjcxb
  • 开始时间 开始时间
C

cddyjcxb

Unregistered / Unconfirmed
GUEST, unregistred user!
用ICS中的WSocket控件做ASP DNS组件时,发现WSocket不执行OnDnsLookupDone事件。造成查询不了DNS。
源文件如下:
//*****************DNS.DPR
library DNS;

{%File 'ConnectDns.asp'}

uses
ComServ,
DNS_TLB in 'DNS_TLB.pas',
DnsLookup in 'DnsLookup.pas' {ConnectDns: CoClass};

exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;

{$R *.TLB}

{$R *.RES}

begin
end.

//*******************DnsLookup.pas
unit DnsLookup;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
ComObj, ActiveX, AspTlb, DNS_TLB, StdVcl,WinSock, WSocket,Classes,SysUtils;

type
TConnectDns = class(TASPObject, IConnectDns)
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
function DnsLookup(const DomainDns: WideString): OleVariant; safecall;
private
WSocket:TWSocket;
ReturnIpList:String;
procedure DnsLookupDone(Sender: TObject;Error: Word);
end;

implementation

uses ComServ;

procedure TConnectDns.OnEndPage;
begin
WSocket.Free;
inherited OnEndPage;
end;

procedure TConnectDns.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
WSocket:=TWSocket.Create(nil);
WSocket.OnDnsLookupDone:=DnsLookupDone;
end;

function TConnectDns.DnsLookup(const DomainDns: WideString): OleVariant;
begin
WSocket.DnsLookup(DomainDns);
Result:=ReturnIpList;
end;

procedure TConnectDns.DnsLookupDone(Sender: TObject;Error: Word);
var
i:integer;
begin
if Error = 0 then begin
for i:=0 to WSocket.DnsResultList.Count-1 do
ReturnIpList := ReturnIpList+WSocket.DnsResultList;
end
else
ReturnIpList:= 'NOT FOUND, ERROR #' + IntToStr(Error);
end;

initialization
TAutoObjectFactory.Create(ComServer, TConnectDns, Class_ConnectDns,
ciMultiInstance, tmApartment);
end.

//***************dns.asp
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> You should see the results of your Delphi Active Server method below </H3>
</CENTER>
<HR>
<% Set DelphiASPObj = Server.CreateObject("DNS.ConnectDns")
Response.write DelphiASPObj.DnsLookup("news.sina.com.cn")
%>
<HR>
</BODY>
</HTML>
----------------------
 
DNS服务器IP地址没有[8D]
 
procedure TConnectDns.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
WSocket:=TWSocket.Create(nil);
WSocket.OnDnsLookupDone:=DnsLookupDone;
WSocket.Addr:='202.101.23.18';
WSocket.Port:='53';
end;
加了DNS地址与端口也没用!!!!!!就是WSocket不触发OnDnsLookupDone事件。
另:在FORM中不需要给地址也可以!!!!
 
一天了!有谁会啊???????/
用DELPHI编ASP组件有限制吗???如在编写ASP组件程序手工创建另一组件(如TWSocket组件)。难道就不能调用它的事件吗?如果真的话。那用DELPHI编ASP组件没太大意思!?!?!%#¥%#¥#·%
 
DNS协议
DNS是使用UDP
使用ICS中的TDnsQuery组件,在DnsQuery.pas单元
 
unit Unit12;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
ComObj, ActiveX, AspTlb, dnst_TLB, StdVcl, DnsQuery,winsock,SysUtils;

type
Tconnectdns = class(TASPObject, Iconnectdns)
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
function DnsLookup(const host: WideString): OleVariant; safecall;
private
IpList:String;
DnsQuery1: TDnsQuery;
procedure DnsQuery1RequestDone(Sender: TObject; Error: Word);
end;

implementation

uses ComServ;

procedure Tconnectdns.OnEndPage;
begin
DnsQuery1.Free;
inherited OnEndPage;
end;

procedure Tconnectdns.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
DnsQuery1:=TDnsQuery.Create(nil);
DnsQuery1.OnRequestDone:=DnsQuery1RequestDone;
DnsQuery1.Addr:='202.101.23.18';
end;

function Tconnectdns.DnsLookup(const host: WideString): OleVariant;
begin
DnsQuery1.ALookup(host);
result:=IpList;
end;

procedure TConnectDns.DnsQuery1RequestDone(Sender: TObject; Error: Word);
var
I : Integer;
nIndex : Integer;
begin
if Error <> 0 then begin
IpList:='Error #' + IntToStr(Error);
Exit;
end;
for I := 0 to DnsQuery1.ResponseANCount - 1 do begin
nIndex := DnsQuery1.AnswerTag;
IpList:=IpList+' Address : ' + StrPas(inet_ntoa(DnsQuery1.Address[nIndex]));
end;
end;

initialization
TAutoObjectFactory.Create(ComServer, Tconnectdns, Class_connectdns,
ciMultiInstance, tmApartment);
end.


楼上的兄弟,改为DNSQuery也不行呢
 
后退
顶部