unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, ScktComp, StdCtrls, ComCtrls;
type
TIP =
class(TForm)
Label1: TLabel;
Label2: TLabel;
ClientVerbinden: TButton;
ClientTrennen: TButton;
ServerVerbinden: TButton;
ServerTrennen: TButton;
ClientSocket1: TClientSocket;
ServerSocket1: TServerSocket;
Beenden: TButton;
StatusBar1: TStatusBar;
ClientSenden: TButton;
ServerSenden: TButton;
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
Memo2: TMemo;
procedure ClientVerbindenClick(Sender: TObject);
procedure ServerVerbindenClick(Sender: TObject);
procedure BeendenClick(Sender: TObject);
procedure ClientTrennenClick(Sender: TObject);
procedure ServerTrennenClick(Sender: TObject);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSendenClick(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSendenClick(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
IP:TIP;
implementation
{$R *.DFM}
procedure TIP.ClientVerbindenClick(Sender: TObject);
//Verbindung des Clienten
begin
clientsocket1.active:=true;
//Verbindung wird aktiviert
end;
procedure TIP.ServerVerbindenClick(Sender: TObject);
//Verbindung des Servers
begin
serversocket1.active:=true;
//Verbindung wird aktiviert
end;
procedure TIP.BeendenClick(Sender: TObject);
begin
close;
//Programm wird beendet
end;
procedure TIP.ClientTrennenClick(Sender: TObject);
begin
clientsocket1.active:=false;
//Client wird getrennt
end;
procedure TIP.ServerTrennenClick(Sender: TObject);
begin
serversocket1.active:=false;
//Server wird getrennt
end;
procedure TIP.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.simpletext:='
Verbindung wurde getrennt';
//Statusanzeige
end;
procedure TIP.ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
statusbar1.simpletext:='
Error. Verbindung wird getrennt!';
//Statusanzeige
clientsocket1.Active:=false;
//Bei Fehler wird Verbindung getrennt
end;
procedure TIP.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.simpletext:='
Verbunden';
//Statusanzeige
end;
procedure TIP.ClientSendenClick(Sender: TObject);
begin
clientsocket1.socket.sendtext(edit1.text);
end;
procedure TIP.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
empfang:
string;
begin
empfang:=socket.receivetext;
memo2.lines.add(empfang);
end;
procedure TIP.ServerSendenClick(Sender: TObject);
begin
serversocket1.socket.sendtext(Edit2.text);
end;
procedure TIP.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
var
empfang2:
string;
begin
empfang2:=socket.receivetext;
memo1.lines.add(empfang2);
end;
end.