unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp, XPMan;
type
TForm1 =
class(TForm)
Label1: TLabel;
Port: TEdit;
GroupBox1: TGroupBox;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Senden: TEdit;
User: TLabel;
Server: TServerSocket;
XPManifest1: TXPManifest;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ServerClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerClientError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button4Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Userzahl:Integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Server.Port:=strtoint(Port.Text);
Server.Active:=True;
Button1.Enabled:=False;
Button2.Enabled:=True;
Memo1.Lines.Add('
Status: Server gestartet.');
Memo1.Lines.Add(Viel Spaß) ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Server.Port:=strtoint(Port.Text);
Server.Active:=False;
Button1.Enabled:=True;
Button2.Enabled:=False;
Memo1.Lines.Add('
Status: Server angehalten.');
sleep(600);
Memo1.Clear;
Memo1.Lines.Add('
Chatserver v1.0 (by Fabian Cernota)');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Memo1.Lines.Clear;
Memo1.Lines.Add('
Server 1.0');
end;
procedure TForm1.Button4Click(Sender: TObject);
var i:Integer;
begin
for i := 0
to Server.Socket.ActiveConnections - 1
do
Server.Socket.Connections[i].SendText('
Nachricht vom Server: ' + Senden.Text);
Memo1.Lines.Add('
Nachricht vom Server: ' + Senden.Text);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Server.Active:=False;
Application.Terminate;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Server.Active:=False;
end;
procedure TForm1.ServerClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
Memo1.Lines.Add('
Status: Client ' + Socket.RemoteAddress + '
verbunden.');
Userzahl:=Userzahl +1;
User.Caption:='
User: ' + inttostr(Userzahl);
end;
procedure TForm1.ServerClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo1.Lines.Add('
Status: Client ' + Socket.RemoteAddress + '
getrennt.');
Userzahl:=Userzahl -1;
User.Caption:='
User: ' + inttostr(Userzahl);
end;
procedure TForm1.ServerClientError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
Memo1.Lines.Add('
Status: Client ' + Socket.RemoteAddress + '
hat den Fehler: ' + inttostr(Errorcode));
Userzahl:=Userzahl -1;
User.Caption:='
User: ' + inttostr(Userzahl);
end;
procedure TForm1.ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
var i:integer;
Nachricht:AnsiString;
begin
Nachricht:=Socket.RemoteAddress + '
: ' + Socket.ReceiveText;
Memo1.Lines.Add(Nachricht);
for i := 0
to Server.Socket.ActiveConnections - 1
do
Server.Socket.Connections[i].SendText(Nachricht);
end;
end.