Oppure

Loading
02/05/11 15:43
Goblin
usa il nome e/o l'indirizzo fisico (mac address), per discriminarli
Ibis redibis non morieris in bello
02/05/11 17:02
smanettone83
Postato originariamente da Goblin:

usa il nome e/o l'indirizzo fisico (mac address), per discriminarli


si esatto quoto
aaa
04/05/11 15:59
givex8
Salve a tutti, ho risolto definitivamente in questo modo:

PS: lstClients è la ListBox con l'elenco dei client connessi.

Quando un Client si connette:

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
var
  ClientName: String;
begin
  ClientName := Socket.RemoteAddress;
  lstClients.Items.AddObject(ClientName, Socket);
end;



Quando un Client si disconnette:

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
var
  Index: Integer;
begin
  Socket.Data := nil;
  Index := lstClients.Items.IndexOfObject(Socket);
  if Index >= 0 then lstClients.Items.Delete(Index);
end;



Quando un Client si disconnette brutalmente (es. chiusura del programma dal Task Manager), nell'evento OnError:

procedure TForm1.ServerSocket1ClientError(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
var
  Index: Integer;
begin
  Socket.Data := nil;
  Index := lstClients.Items.IndexOfObject(Socket);
  if Index >= 0 then
  begin
    if ErrorEvent = eeDisconnect then lstClients.Items.Delete(Index);
  end;
end;
Ultima modifica effettuata da givex8 04/05/11 16:02
aaa
04/05/11 18:33
smanettone83
bene ;)
aaa
04/05/11 18:34
smanettone83
bene ;)
aaa