Einzelnen Beitrag anzeigen

DelphiProgrammer

Registriert seit: 5. Apr 2013
Ort: Kennste eh net! wer weiss, wer weiss o.o
43 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#8

AW: Client<>Socket Chat Problem

  Alt 30. Jan 2014, 14:58
Hier noch der Client
Delphi-Quellcode:
unit CClient;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ScktComp, XPMan;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    EdNick: TEdit;
    EdIP: TEdit;
    EdPort: TEdit;
    Button1: TButton;
    XPManifest1: TXPManifest;
    memosend: TMemo;
    Label4: TLabel;
    Btnsend: TButton;
    MemoReceive: TMemo;
    ClientSocket1: TClientSocket;
    procedure ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket);
    procedure ClientSocket1Disconnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure BtnsendClick(Sender: TObject);
    procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  ClientSocket1.Host:=EdIP.Text;
  ClientSocket1.Port:=StrToInt(EdPort.Text);
  ClientSocket1.Open;
end;

procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
var msg:string;
begin
  msg:=Socket.ReceiveText; //Der Empfangene Text wird in der Variable msg gespeichert
  MemoReceive.Lines.Add(msg); //Die Nachricht wird in das Memo eingefügt
end;

procedure TForm1.BtnsendClick(Sender: TObject);
var msg: String;
begin
  if UpperCase(EdNick.Text) = 'ADMINISTRATORthen
  begin
    ShowMessage('Please choose an another nickname.');
  end
  else
  begin
  msg:=MemoSend.Text; //Text zum Senden wird in "msg" gespeichert
  msg:= EdNick.Text +': '+msg; //Hinzufügen von Nickname
  ClientSocket1.Socket.SendText(msg); //Senden der Nachricht
  MemoSend.Clear;
  end;
end;

procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  BtnSend.Enabled:=false;
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  BtnSend.Enabled:=true;
end;

end.
Christopher
---------------------------------------------------
I ♥ Delphi
  Mit Zitat antworten Zitat