Solved

TServerSocket's OnClientDisconnect ?

Posted on 2003-10-23
4
361 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
ID: 9612740
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
ID: 9612753
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
ID: 9615305
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
ID: 9616003
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Run video youtube webbrowse 10 57
URL for downloading Google Chrome for Win XP 2 120
Working with hours 3 46
drawing animated level bar based on numbers 3 88
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

912 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

21 Experts available now in Live!

Get 1:1 Help Now