Einzelnen Beitrag anzeigen

Benutzerbild von hincapie
hincapie

Registriert seit: 24. Mär 2005
200 Beiträge
 
Delphi 5 Professional
 
#2

Re: Methode zum wiederfinden eines Indy-Thread

  Alt 30. Mär 2007, 07:17
In etwa so? (entnommen dem IndyChat-Demo)
Delphi-Quellcode:
procedure TfrmMain.tcpServerExecute(AThread: TIdPeerThread);
var
  Client : TSimpleClient;
  Com, // System command
  Msg : String;
 begin
{ Get the text sent from the client }
  Msg := AThread.Connection.ReadLn;
{ Get the clients package info }
  Client := Pointer(AThread.Data);
{ Check to see if the clients name has been assigned yet }
  if Client.Name = 'Logging Inthen
    begin
    { if not, assign the name and announce the client }
      Client.Name := Msg;
      UpdateClientList;
      BroadcastMessage('System', RipName(Msg) + ' has just logged in.');
      AThread.Connection.WriteLn(memEntry.Lines.Text);
    end
  else
  { If name is set, then send the message }

  if Msg[1] <> '@then
    begin
    { Not a system command }
       BroadcastMessage(RipName(Client.Name), Msg);
    end
  else
    begin
    { System command }
      Com := UpperCase(Trim(Copy(Msg, 2, Pos(':', Msg) -2)));
      Msg := UpperCase(Trim(Copy(Msg, Pos(':', Msg) +1, Length(Msg))));
      if Com = 'CLIENTSthen
        AThread.Connection.WriteLn( '@' + 'clients:' +
                                    lbClients.Items.CommaText);
   ...
Die Klasse TSimpleClient sieht dabei so aus:
Delphi-Quellcode:
type
  TSimpleClient = class(TObject)
    DNS,
    Name : String;
    ListLink : Integer;
    Thread : Pointer;
  end;
  Mit Zitat antworten Zitat