D
daifan
Unregistered / Unconfirmed
GUEST, unregistred user!
我用DELPHI写一个ASP组件,其中使用了TClientSocket进行通讯,此外有一个服务器端,
在我执行了页面后,系统现实超时,但是服务器程序现实已经将数据发送给控件,那就是
说动态创建的TClientSocket的OnRead事件没有被触发,大家帮我看看.....
unit Unit1;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, AspTlb, PMAsp_TLB, StdVcl, ScktComp, SysUtils, DateUtils;
type
TeTermToERP = class(TASPObject, IeTermToERP)
private
blnReceived : Boolean;
strRecv : String;
PMSocket : TClientSocket;
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
procedure HelloASP; safecall;
function Get_BukPNRdetail(var PnrNo: OleVariant): OleVariant; safecall;
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
end;
implementation
uses ComServ;
procedure TeTermToERP.OnEndPage;
begin
inherited OnEndPage;
end;
procedure TeTermToERP.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;
procedure TeTermToERP.HelloASP;
begin
Response.Write('我的第一个ASP组件.HAHA....');
end;
function TeTermToERP.Get_BukPNRdetail(var PnrNo: OleVariant): OleVariant;
var
AThen: TDateTime;
begin
PMSocket := TClientSocket.Create(nil);
PMSocket.Host := '127.0.0.1';
PMSocket.Port := 7501;
PMSocket.ClientType := ctBlocking;
PMSocket.OnRead := ClientSocketRead;
PMSocket.OnError := ClientSocketError;
blnReceived := FALSE;
strRecv := '';
PMSocket.Open;
AThen := Now;
while PMSocket.Active = FALSE do
begin
strRecv := 'NOT CONNECTED';
if SecondsBetween(Now,AThen) > 6 then break;
end;
if PMSocket.Active then
begin
PMSocket.Socket.SendText(PnrNo);
AThen := Now;
while blnReceived = FALSE do
begin
if SecondsBetween(Now,AThen) < 6 then continue;
blnReceived := TRUE;
strRecv := 'OUT OF TIME';
end;
PMSocket.Close;
end;
PMSocket.Free;
Result := 'GET THE DETAIL OF ' + PnrNo + ': '+ strRecv;
end;
procedure TeTermToERP.ClientSocketError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
ErrorCode := 0;
end;
procedure TeTermToERP.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
strRecv := Socket.ReceiveText;
blnReceived := TRUE;
end;
initialization
TAutoObjectFactory.Create(ComServer, TeTermToERP, Class_eTermToERP,
ciMultiInstance, tmApartment);
end.
在我执行了页面后,系统现实超时,但是服务器程序现实已经将数据发送给控件,那就是
说动态创建的TClientSocket的OnRead事件没有被触发,大家帮我看看.....
unit Unit1;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, AspTlb, PMAsp_TLB, StdVcl, ScktComp, SysUtils, DateUtils;
type
TeTermToERP = class(TASPObject, IeTermToERP)
private
blnReceived : Boolean;
strRecv : String;
PMSocket : TClientSocket;
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
procedure HelloASP; safecall;
function Get_BukPNRdetail(var PnrNo: OleVariant): OleVariant; safecall;
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
end;
implementation
uses ComServ;
procedure TeTermToERP.OnEndPage;
begin
inherited OnEndPage;
end;
procedure TeTermToERP.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;
procedure TeTermToERP.HelloASP;
begin
Response.Write('我的第一个ASP组件.HAHA....');
end;
function TeTermToERP.Get_BukPNRdetail(var PnrNo: OleVariant): OleVariant;
var
AThen: TDateTime;
begin
PMSocket := TClientSocket.Create(nil);
PMSocket.Host := '127.0.0.1';
PMSocket.Port := 7501;
PMSocket.ClientType := ctBlocking;
PMSocket.OnRead := ClientSocketRead;
PMSocket.OnError := ClientSocketError;
blnReceived := FALSE;
strRecv := '';
PMSocket.Open;
AThen := Now;
while PMSocket.Active = FALSE do
begin
strRecv := 'NOT CONNECTED';
if SecondsBetween(Now,AThen) > 6 then break;
end;
if PMSocket.Active then
begin
PMSocket.Socket.SendText(PnrNo);
AThen := Now;
while blnReceived = FALSE do
begin
if SecondsBetween(Now,AThen) < 6 then continue;
blnReceived := TRUE;
strRecv := 'OUT OF TIME';
end;
PMSocket.Close;
end;
PMSocket.Free;
Result := 'GET THE DETAIL OF ' + PnrNo + ': '+ strRecv;
end;
procedure TeTermToERP.ClientSocketError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
ErrorCode := 0;
end;
procedure TeTermToERP.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
strRecv := Socket.ReceiveText;
blnReceived := TRUE;
end;
initialization
TAutoObjectFactory.Create(ComServer, TeTermToERP, Class_eTermToERP,
ciMultiInstance, tmApartment);
end.