unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdCustomTCPServer,
IdCustomHTTPServer, IdHTTPServer;
type
TForm4 =
class(TForm)
IdHTTPServer1: TIdHTTPServer;
Button1: TButton;
Label1: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure IdHTTPServer1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
procedure IdHTTPServer1AfterBind(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.Button1Click(Sender: TObject);
begin
IdHTTPServer1.Active := false;
IdHTTPServer1.DefaultPort := 8888;
// Port 8888 ist Standard
try
IdHTTPServer1.Active := true;
except
raise;
end;
if IdHTTPServer1.Active
then
begin
label1.Caption := '
Server ist: ONLINE an Port 8888';
end;
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
try
IdHTTPServer1.Active := false;
except
raise;
end;
if not IdHTTPServer1.Active
then
begin
Label1.Caption := '
Server ist: OFFLINE';
end;
end;
procedure TForm4.IdHTTPServer1AfterBind(Sender: TObject);
begin
//
end;
procedure TForm4.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
Var
Stream: TFilestream;
TheString :
String;
begin
if ARequestInfo.Document = '
/'
then begin
AResponseInfo.ContentType := '
image/jpeg';
IF fileexists('
test.jpg') = true
then ARequestInfo.Document := '
test.jpg';
end;
Stream := TfileStream.Create('
test.jpg', fmOpenRead
or fmShareDenyWrite );
AResponseInfo.ContentStream := Stream;
setlength(TheString, stream.size);
stream.
Read(TheString[1], stream.size);
end;
end.