unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, XPMan, ScktComp;
type TChatNachricht =
Record
nick:
string[255];
chat:
string[255];
state:
string[255];
end;
type
TForm1 =
class(TForm)
Label1: TLabel;
connect: TButton;
ip: TEdit;
Label2: TLabel;
port: TEdit;
Label3: TLabel;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
GroupBox3: TGroupBox;
Edit3: TEdit;
GroupBox4: TGroupBox;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Image7: TImage;
sclient: TClientSocket;
Button7: TButton;
XPManifest1: TXPManifest;
Memo1: TMemo;
chat: TEdit;
send: TButton;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
nick: TEdit;
procedure sendClick(Sender: TObject);
procedure connectClick(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure sclientconnect (Sender: TObject; Socket: TCustomWinSocket);
procedure sclientread (Sender: TObject; Socket: TCustomWinSocket);
procedure sclientconnecting (Sender: TObject; Socket: TCustomWinSocket);
procedure sclienterror (Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure sclientlookup (Sender: TObject; Socket: TCustomWinSocket);
procedure sclientdisconnect (Sender: TObject; Socket: TCustomWinSocket);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button7Click(Sender: TObject);
begin
close;
end;
//---------------------------------------------------------------------------------------------------------
procedure TForm1.sclientlookup(Sender: TObject; Socket: TCustomWinSocket);
begin
Memo1.Lines.Add ('
State: Searching Server');
end;
procedure TForm1.sclientConnecting(Sender: TObject; Socket: TCustomWinSocket);
begin
Memo1.Lines.Add ('
State: Connecting...');
end;
procedure TForm1.sclientconnect (Sender: TObject; Socket: TCustomWinSocket);
var Nachricht: TChatNachricht;
begin
Memo1.Lines.Add ('
State: Connected');
Nachricht.nick := nick.Text;
Nachricht.state := '
newuser';
sclient.Socket.SendBuf (Nachricht, SizeOf(Nachricht));
Memo1.Lines.Add(nick.Text);
end;
procedure TForm1.sclientError (Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
Memo1.Lines.Add ('
State: Error ' + IntToStr(ErrorCode));
ErrorCode := 0;
end;
procedure TForm1.sclientdisconnect(Sender: TObject;
Socket: TCustomWinSocket);
var Nachricht: TChatNachricht;
begin
Memo1.Lines.Add ('
State: Disconnected');
end;
//*********************************** Client READ **********************************************************
procedure TForm1.sclientRead (Sender: TObject; Socket: TCustomWinSocket);
var Nachricht: TChatNachricht;
begin
Socket.ReceiveBuf (Nachricht, SizeOf(Nachricht));
if (Nachricht.state = '
chat')
then begin
Memo1.Lines.add (Nachricht.nick+'
: '+Nachricht.chat);
end;
end;
//---------------------------------------------------------------------------------------------------------
procedure TForm1.connectClick(Sender: TObject);
var
Nachricht :TChatNachricht;
begin
if connect.caption = '
Connect'
then begin
sclient.Host :=
ip.text;
sclient.Port := strtoint(port.text);
ip.Enabled := false;
port.Enabled := false;
nick.Enabled := false;
sclient.Active := true;
//Nachricht.nick := nick.text;
//Nachricht.state := 'newuser';
//sclient.Socket.SendBuf (Nachricht, SizeOf(Nachricht)); */
connect.caption := '
Disconnect';
end
else
if connect.caption = '
Disconnect'
then begin
sclient.Active := false;
ip.Enabled := true;
port.Enabled := true;
nick.Enabled := true;
connect.caption := '
Connect';
Memo1.Lines.SaveToFile('
Pokerchat-log.txt');
end;
end;
//------------- Client Send -----------------------------------------------------------------
procedure TForm1.sendClick(Sender: TObject);
var
Nachricht: TChatNachricht;
begin
if (sclient.active)
then begin
nachricht.state := '
chat';
nachricht.chat := chat.text;
nachricht.nick := nick.text;
sclient.Socket.SendBuf (Nachricht, SizeOf(Nachricht));
chat.Text := '
';
end
else
begin
memo1.lines.add('
Not connected!');
end;
end;
end.