Solved

TServerSocket's OnClientDisconnect ?

Posted on 2003-10-23
4
356 Views
Last Modified: 2010-04-05
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;
0
Comment
Question by:shaneholmes
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:gmayo
Comment Utility
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.
0
 
LVL 8

Accepted Solution

by:
gmayo earned 150 total points
Comment Utility
You could set a flag in your Connect/Disconnect handlers and have a timer running. If the timer triggers and the flag is set, then update the clients list.

procedure TfrmMain.OnTimerTimer(Sender : TObject);
begin
   if UpdateRequired then UpdateClients;
   UpdateRequired := false;
end;

procedure TfrmMain.sckMainClientConnect(Sender: TObject;
 Socket: TCustomWinSocket);
begin
   UpdateRequired := true;
end;

procedure TfrmMain.sckMainClientDisconnect(Sender: TObject;
 Socket: TCustomWinSocket);
begin
   UpdateRequired := true;
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;

Geoff M.
0
 
LVL 11

Author Comment

by:shaneholmes
Comment Utility
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.
0
 
LVL 11

Author Comment

by:shaneholmes
Comment Utility
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
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now