Hello: I am using following simple code in OnConnect() and OnDisconnect() of Indy TCP Server to determine number of clients. int TotalClients; TList *ClientsList; ClientsList = IdTCPServer1->Contexts->LockList(); try { TotalClients = ClientsList->Count; } __finally { IdTCPServer1->Contexts->UnlockList(); } TotalClients increments ok when I connect multiple clients but when all the clients are disconnected, the TotalClients number remains at 1 instead of going to 0. What is going wrong here? Thanks, Sudesh
![]() |
0 |
![]() |
Sudesh wrote: > TotalClients increments ok when I connect multiple clients but when > all the clients are disconnected, the TotalClients number remains at 1 > instead of going to 0. In the OnDisconnect event, the client that is triggering the event has not been removed from the list yet. You will have to account for that, eg: {code} int __fastcall TMyForm::GetClientCount() { int Clients; TList *ClientsList = IdTCPServer1->Contexts->LockList(); try { Clients = ClientsList->Count; } __finally { IdTCPServer1->Contexts->UnlockList(); } return Clients; } void __fastcall TMyForm::IdTCPServer1Connect(TIdContext *AContext) { int TotalClients = GetClientCount(); //... } void __fastcall TMyForm::IdTCPServer1Disconnect(TIdContext *AContext) { int TotalClients = GetClientCount() - 1; //... } {code} -- Remy Lebeau (TeamB)
![]() |
0 |
![]() |
Oh I see. Thanks Remy, Sudesh "Remy Lebeau (TeamB)" wrote in message news:729786@forums.embarcadero.com... Sudesh wrote: > TotalClients increments ok when I connect multiple clients but when > all the clients are disconnected, the TotalClients number remains at 1 > instead of going to 0. In the OnDisconnect event, the client that is triggering the event has not been removed from the list yet. You will have to account for that, eg: {code} int __fastcall TMyForm::GetClientCount() { int Clients; TList *ClientsList = IdTCPServer1->Contexts->LockList(); try { Clients = ClientsList->Count; } __finally { IdTCPServer1->Contexts->UnlockList(); } return Clients; } void __fastcall TMyForm::IdTCPServer1Connect(TIdContext *AContext) { int TotalClients = GetClientCount(); //... } void __fastcall TMyForm::IdTCPServer1Disconnect(TIdContext *AContext) { int TotalClients = GetClientCount() - 1; //... } {code} -- Remy Lebeau (TeamB)
![]() |
0 |
![]() |