unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp;
type
TMainForm =
class(TForm)
SS1: TServerSocket;
Button1: TButton;
Button2: TButton;
procedure SS1ClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
index:TStringList;
implementation
{$R *.dfm}
procedure TMainForm.SS1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
sl:TStringList;
s:
string;
i:integer;
begin
sl:=TStringList.Create;
sl.Text:=Socket.ReceiveText;
if sl[0]='
GET / HTTP/1.1'
then begin
Socket.SendText(
index.Text);
Socket.Close;
end;
if sl[0]='
POST / HTTP/1.1'
then begin
s:=sl[sl.Count-1];
i:=pos('
&go=',s);
if i>0
then begin
Delete(s,i,length(s)-i+1);
end;
if pos('
text=',s)=1
then Delete(s,1,5);
while pos('
%0D%0A',s)>0
do begin
i:=pos('
%0D%0A',s);
Delete(s,i,6);
Insert(#13#10,s,i);
end;
Socket.SendText(s);
Socket.Close;
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
SS1.Port:=8989;
index:=TStringList.Create;
if FileExists(ExtractFileDir(Application.ExeName) + '
\index.htm')
then
index.LoadFromFile(ExtractFileDir(Application.ExeName) + '
\index.htm');
SS1.Active:=true;
end;
procedure TMainForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
SS1.Active:=false;
end;
end.