Powiedz: JAK :]
A, chociażby tak:
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls, strutils;
type
TForm1 = class(TForm)
server: TServerSocket;
Memo1: TMemo;
procedure serverClientRead(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const
rootfile='index.html';
implementation
{$R *.dfm}
procedure TForm1.serverClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
s:array [0..1023] of char;
l:integer;
request, temp:tstringlist;
begin
l:=socket.ReceiveLength;
socket.ReceiveBuf(s, l);
request:=tstringlist.Create;
temp:=tstringlist.Create;
request.Text:=s;
memo1.Text:=s;
temp.Text:=request[0];
temp.Text:=ansireplacetext(request[0], ' ', #13#10);
temp[1]:=ansireplacetext(copy(temp[1], 2, length(temp[1])-1), '/', '');
temp[1]:=ansireplacetext(temp[1], '%20', ' ');
if temp[1]='' then
temp[1]:=rootfile;
if not fileexists(extractfilepath(application.ExeName)+'WWW'+temp[1]) then
begin
memo1.Lines.Add('Błąd - '+extractfilepath(application.ExeName)+'WWW'+temp[1]);
temp[1]:=extractfilepath(application.ExeName)+'Error.tpl';
end
else
temp[1]:=extractfilepath(application.ExeName)+'WWW'+temp[1];
memo1.Lines.Add(temp[1]);
socket.SendStream(tfilestream.Create(temp[1], fmopenread or fmsharedenywrite));
socket.Close;
end;
end.
to najbanalniejszy serwer HTTP, który nie obsługuje wielu rzeczy, ale działa i jak widac, nie jest zbyt skomplikowany. Ruszysz głową, przejrzysz specyfikację HTTP albo chociaż obejrzysz jakimś snifferem co wysyła przeglądarka i starczy.