unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AppEvnts, ExtCtrls, ScktComp;
type
TForm1 =
class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ComboBox1: TComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Timer1: TTimer;
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Delay(time: word);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
ServerSocket1: TServerSocket;
Label6.Caption:=IdIPWatch1.LocalIP;
//Damit oben im Fenster schon beim FormCreate die aktuelle IP-Adresse angezeigt wird
Button1.Enabled:=false;
//Damit man nicht schon vorher draufdrückt
Button2.Enabled:=false;
// -''-
implementation
{$R *.dfm}
procedure TForm1.delay(time:word);
var Start: Integer;
begin Start:=GetTickCount;
while (GetTickCount)-(Start) <= time
do Application.ProcessMessages;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ServerSocket1 := TServerSocket.Create(
nil);
ServerSocket1.OnClientRead:=Form1.ServerSocket1ClientRead;
ServerSocket1.OnClientConnect:=Form1.ServerSocket1ClientConnect;
end;
procedure ServerSocket1ClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
Form1.Show;
Memo1.Lines.Add(Socket.ReceiveText);
//Der Code, der ausgeführt werden soll, wenn ein Text von einem Client ankommt
end;
procedure ServerSocket1ClientConect(Sender: TObject; Socket: TCustomWinSocket);
begin
//Der Code, der ausgeführt werden soll, wenn ein Client sich verbindet
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Nickname:=Edit3.Text;
Button3.Enabled:=false;
Edit3.Enabled:=false;
Button2.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ClientSocket1.Host:=Edit2.Text;
ClientSocket1.Active:=true;
Button2.Enabled:=false;
Edit2.Enabled:=false;
Button1.Enabled:=true;
Nachricht:=Edit3.Text+'
hat den Raum betreten'; delay(500);
ClientSocket1.Socket.SendText(Nachricht);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if (ClientSocket1.Active=true)
and (Edit1.Text<>'
')
then
ClientSocket1.Socket.SendText(NickName+'
: '+Edit1.Text);
Edit1.Text:='
';
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label3.Caption:=IdIPWatch1.LocalIP;
end;
end.