unit Client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
TForm1 =
class(TForm)
nicklbl: TLabel;
nicked: TEdit;
nickbut: TButton;
adresseed: TEdit;
connectbut: TButton;
adresselbl: TLabel;
chatlog_memo: TMemo;
nachrichted: TEdit;
sendenbut: TButton;
ClientSocket: TClientSocket;
procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure sendenbutClick(Sender: TObject);
procedure connectbutClick(Sender: TObject);
procedure nickbutClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
nickname :
String;
implementation
{$R *.dfm}
procedure TForm1.ClientSocketError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
ErrorCode := 0;
end;
procedure TForm1.ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
adresselbl.Enabled := false;
adresseed.Enabled := false;
connectbut.Enabled := false;
nicklbl.Enabled := true;
nicked.Enabled := true;
nickbut.Enabled := true;
end;
procedure TForm1.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
str:
string;
begin
str := ClientSocket.Socket.ReceiveText;
chatlog_memo.Lines.Add(str);
end;
procedure TForm1.sendenbutClick(Sender: TObject);
begin
chatlog_memo.Lines.Add(nickname + '
sagt: ' + nachrichted.Text);
ClientSocket.Socket.SendText(nickname + '
sagt: ' + nachrichted.Text);
nachrichted.Text := '
';
end;
procedure TForm1.connectbutClick(Sender: TObject);
begin
ClientSocket.Host := adresseed.Text;
ClientSocket.Port := 2000;
ClientSocket.Active := true;
end;
procedure TForm1.nickbutClick(Sender: TObject);
begin
nickbut.Enabled := false;
nicked.Enabled := false;
nicklbl.Enabled := false;
nickname := nicked.Text;
chatlog_memo.Enabled := true;
nachrichted.Enabled := true;
sendenbut.Enabled := true;
end;