Ya se como detectar la entrada y salida de un cliente
Cogí el ejemplo del chat de las indy y en el evento onconect del tidtcpserver detecto cuando se conecta un nuevo cliente y el el diconect cuando se desconecta y lo hago de la siguiente manera :
procedure TfrmMain.tcpServerConnect(AThread: TIdPeerThread);
var
Client : TSimpleClient;
begin
{ Send a welcome message, and prompt for the users name }
AThread.Connection.WriteLn('ISD Connection Established...');
AThread.Connection.WriteLn('Please send valid login sequence...');
AThread.Connection.WriteLn('Your Name:');
{ Create a client object }
Client := TSimpleClient.Create;
{ Assign its default values }
Client.DNS := AThread.Connection.LocalName;
Client.Name := 'Logging In';
Client.ListLink := lbClients.Items.Count;
{ Assign the thread to it for ease in finding }
Client.Thread := AThread;
{ Add to our clients list box }
lbClients.Items.Add(Client.Name);
{ Assign it to the thread so we can identify it later }
AThread.Data := Client;
{ Add it to the clients list }
Clients.Add(Client);
showmessage('Se ha conectado'+' '+client.Name);
end;
y con showmessage tambien lo hago en el evento ondisconect pero hay un problema ahora por qué en el mensage que se muestra me sale:
En el OnConect
Se ha conectado Logging In <---- aquí no me sale correctamente el nombre del cliente que se ha conectado
En el OnDisconect
Se ha deconectado <---- aquí si me sale correctamente el nombre del cliente que se ha desconectado
Última edición por kakesoft fecha: 30-04-2005 a las 22:58:18.
|