Recent

Author Topic: INDY -SOLVED - How to properly disconnect client from indyTCPserver  (Read 910 times)

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
 
Code: Pascal  [Select][+][-]
  1.   begin
  2.    for counter := 0 to ServerClientsCount-1 do
  3.       if IdTCPServer1.Contexts[counter] doNotExistsInMyConnections then
  4.          IdTCPServer1.Contexts[counter].Connection.Disconnect;
  5.    end;

I could not found this syntax "IdTCPServer1.Contexts[counter] " on lazarus indy?

Thank you.
« Last Edit: February 16, 2023, 11:51:28 pm by Mongkey »

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
Re: INDY - How to properly disconnect client from indyTCPserver
« Reply #1 on: February 16, 2023, 02:59:58 pm »
Thank you bogen85  :)
SOLVED BY
Code: Pascal  [Select][+][-]
  1.  
  2. Procedure Tf_main.disconnectTCP();
  3. var
  4. List: TIdContextList;
  5.   Context: TIdContext;
  6. begin
  7.   IdTCPSERVER.OnDisconnect  := nil;
  8.   List := IdTCPSERVER.Contexts.LockList;
  9.   //rmemo_listen.Lines.Add('list:' + IntToStr(List.Count));
  10.   try
  11.     for I := 0 to List.Count - 1 do
  12.     begin
  13.       Context := TIdContext(List[I]);
  14.       Context.Connection.Disconnect;
  15.     end;
  16.   finally
  17.     IdTCPSERVER.Contexts.UnlockList
  18.   end;
  19. IdTCPSERVER.active := false;
  20. end;
  21.  
« Last Edit: February 16, 2023, 11:53:29 pm by Mongkey »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1314
    • Lebeau Software
Re: INDY - How to properly disconnect client from indyTCPserver
« Reply #2 on: February 17, 2023, 11:46:47 pm »
You DO NOT need to disconnect active clients manually before deactivating the server.  The TIdTCPServer.Active property setter will handle that internally for you.  So, just deactivate the server normally, let Indy do the rest.

Code: Pascal  [Select][+][-]
  1. Procedure Tf_main.disconnectTCP();
  2. begin
  3.   IdTCPSERVER.OnDisconnect := nil;
  4.   IdTCPSERVER.Active := false;
  5. end;
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
Re: INDY -SOLVED - How to properly disconnect client from indyTCPserver
« Reply #3 on: February 18, 2023, 03:10:36 am »
Thank you remi.

 

TinyPortal © 2005-2018