Link to home
Start Free TrialLog in
Avatar of shaneholmes
shaneholmes

asked on

TServerSocket's OnClientDisconnect ?

Why is it that I can't seem to get the OnClientDisconnect of the TServerSocket to report the coorect ActiveConnections?

I am simply creating a ListItem in my ListView for each connection on the OnClientConnect and then removing them in the OnClientDisconnect event - by using a UpdateClients method - see below, however, it doesn't seem to be working for the OnClientDisconnect event. - Any remedy?


procedure TfrmMain.sckMainClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
 pnlClients.Caption:= IntToStr(sckMain.Socket.ActiveConnections)+' Clients';
 UpdateClients;
end;

procedure TfrmMain.sckMainClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
 pnlClients.Caption:= IntToStr(sckMain.Socket.ActiveConnections-1)+' Clients';
 UpdateClients;
end;

procedure TfrmMain.UpdateClients;
var
 Item: TListItem;
 I: Integer;
begin
 lvwClients.Items.BeginUpdate;
 lvwClients.Clear;
 for I:= 0 to sckMain.Socket.ActiveConnections-1 do
 begin
  Item:= lvwClients.Items.Add;
  Item.Caption:= sckMain.Socket.Connections[I].RemoteHost;
 end;
 lvwClients.Items.EndUpdate;
end;
Avatar of gmayo
gmayo
Flag of United Kingdom of Great Britain and Northern Ireland image

Perhaps the OnClientDisconnect is called *before* it is actually removed from the ActiveConnections list? I certainly don't have trouble keeping a list of clients, but I add and remove them from my own list, added when ClientConnect and removed on ClientDisconnect.

Geoff M.
ASKER CERTIFIED SOLUTION
Avatar of gmayo
gmayo
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shaneholmes
shaneholmes

ASKER

K, let me give that a try....btw, i left you a comment on my last post, regarding the Disabling Ctrl-Alt-Del in XP.
Would you please go back and view this and help me out with it.
Sorry about my last comment, it was not you who i left a comment for.

BTW, thanks for the perfect answer to my post!

Shane