unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls, Spin;
type
TForm1 =
class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label2: TLabel;
Label4: TLabel;
mclientverbinden: TButton;
mserververbinden: TButton;
Label5: TLabel;
Label6: TLabel;
textc: TEdit;
Edit1: TEdit;
ssenden: TButton;
csenden: TButton;
ServerMemo: TMemo;
ClientMemo: TMemo;
ClientSocket1: TClientSocket;
ServerSocket1: TServerSocket;
Label7: TLabel;
Label8: TLabel;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
Button1: TButton;
Button2: TButton;
ComboBox1: TComboBox;
Procedure mclientverbindenClick(Sender: TObject);
Procedure ServerSocket1Listen(Sender: TObject; Socket: TCustomWinSocket);
Procedure mserververbindenClick(Sender: TObject);
Procedure ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket);
Procedure csendenClick(Sender: TObject);
Procedure ServerSocket1ClientRead(Sender: TObject; Socket: TCustomWinSocket);
Procedure ClientSocket1ServerRead(Sender: TObject; Socket: TCustomWinSocket);
Procedure ssendenClick(Sender: TObject);
Procedure Button2Click(Sender: TObject);
Procedure Button1Click(Sender: TObject);
Procedure clienttrennen(Sender: TObject; Socket: TCustomWinSocket);
Procedure servertrennen(Sender: TObject; Socket: TCustomWinSocket);
Procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.mclientverbindenClick(Sender: TObject);
begin
//ServerSocket wird geöffnet
ServerSocket1.Port := SpinEdit1.Value;
ServerSocket1.Active := True;
end;
procedure TForm1.ServerSocket1Listen(Sender: TObject; Socket: TCustomWinSocket);
begin
//Wenn ServerSocket Listen erscheint Text
ServerMemo.Lines.Add('
/-- Listen --\');
ServerMemo.Lines.Add('
/-- Port: ' + IntToStr(ServerSocket1.Port));
end;
Procedure Tform1.ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket);
begin
//Wenn ClientSocket verbunden erscheint Text
ClientMemo.lines.Add('
/-- verbunden --\');
ClientMemo.Lines.Add('
/-- Port: ' + IntToStr(clientSocket1.Port));
end;
procedure TForm1.mserververbindenClick(Sender: TObject);
begin
//Client wird verbunden/aktiviert
ClientSocket1.Port := SpinEdit1.Value;
ClientSocket1.Active := True;
ClientSocket1.Address := ComboBox1.Text;
end;
procedure TForm1.csendenClick(Sender: TObject);
begin
// Senden von text an Client
If textc.Text = '
'
then
else
Begin
If textc.Text = '
'
then
else
begin
ClientSocket1.Socket.SendText(textc.Text);
ClientMemo.Lines.Add('
<Client>' + textc.Text);
textc.Text := '
';
end;
end;
end;
Procedure TForm1.ServerSocket1ClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
//Text in ServerMemo schreiben
ServerMemo.lines.Add('
<Client>' + Socket.ReceiveText);
end;
Procedure TForm1.ClientSocket1ServerRead(Sender: TObject; Socket: TCustomWinSocket);
begin
//Text in ClientMemo schreiben
ClientMemo.Lines.Add('
<Server>' + ClientSocket1.Socket.ReceiveText);
end;
procedure TForm1.ssendenClick(Sender: TObject);
begin
// Senden von text an Server
If Edit1.Text = '
'
then
else
Begin
If Edit1.Text = '
'
then
else
begin
ServerSocket1.Socket.Connections[0].SendText(Edit1.Text);
ServerMemo.Lines.Add('
<Server>' + Edit1.Text);
Edit1.Text := '
';
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
// trennen von Client
ClientSocket1.Active := False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// Trennen von Server
ServerSocket1.Active := False;
ServerMemo.Lines.Add('
/-- getrennt --\')
end;
Procedure Tform1.clienttrennen(Sender: TObject; Socket: TCustomWinSocket);
Begin
ClientMemo.Lines.Add('
/-- getrennt --\')
end;
Procedure Tform1.servertrennen(Sender: TObject; Socket: TCustomWinSocket);
Begin
ClientMemo.Lines.Add('
/-- getrennt --\')
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
Begin
//Die Verbindung wird beendet
ServerSocket1.Active := False;
ClientSocket1.Active := False;
end;
end.