|
TClientSocket in ISAPI DLL's
There is a simple way to make Socket connections from a ISAPI DLL to another server. The ISAPI itself is multithreaded so that's already done.
The example opens a socket Blocking (!!!) connection to a local FTP server, sends some data (not really necessary in this case) and receives some data.
The received data is shown as result on a HTML page.
For this example I used CGI-Expert to for the ISAPI DLL generation (for download of a shareware version see Delphi Tools and Utilities)
View the project source (.DPR)
View the unit source (.PAS)
Download the complete source code (.ZIP)
Generated with HyperDelphi
library Project1;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
NsapiEng,
Unit1 in 'Unit1.pas' {DataModule1: TDataModule};
begin
IsMultiThread := TRUE;
Datamodule1:=TDatamodule1.Create(nil);
end.
|
Generated with HyperDelphi
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
HttpEng, GenEng, ScktComp;
type
TDataModule1 = class(TDataModule)
HttpEngine1: TGeneralHttpEngine;
procedure HttpEngine1ExecRequest(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DataModule1: TDataModule1;
implementation
{$R *.DFM}
procedure TDataModule1.HttpEngine1ExecRequest(Sender: TObject);
var
Client: TClientSocket;
SomeData, Data: array[0..127] of char;
ReceivedBytes: integer;
begin
Client := TClientSocket.Create(nil);
Client.Address := '127.0.0.1';
Client.ClientType := ctBlocking;
Client.Port := 21;
FillChar(Data, SizeOf(Data), 0);
SomeData := 'Try Me';
Move(SomeData[0], Data[0], Length(SomeData));
try
Client.Open;
Client.Socket.SendBuf(Data, Length(SomeData));
FillChar(Data, SizeOf(Data), 0);
FillChar(SomeData, SizeOf(SomeData), 0);
ReceivedBytes := Client.Socket.ReceiveBuf(Data, Sizeof(Data));
Move(Data[0], SomeData[0], ReceivedBytes);
Put('<HTML><BODY>' + SomeData + '</BODY></HTML>');
Client.Close;
finally
Client.Free;
end;
end;
end.
|
|
|