How Indy IdTcpServer can transfer data of several lines to a Client?

I Made a simple  "server client"  program with IdTcpServer and IdTcpClient components created with Delphi rad seattled 10.
Is there an efficient way to make the server send  a data to the client at the moment when this client is connected.  
the data should contain several lines when each line Describes each client already connected to the server  ( Id, Age name ...etc)
Thanks in Advance!
bish wakimAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
if you set event Execute of IdTCPServer.... This is taken from Indy demo project:
procedure TfrmMain.tcpServerExecute(AThread: TIdPeerThread);
  Client: TSimpleClient;
  Com, // System command
  Msg: string;
  { Get the text sent from the client }
  Msg := AThread.Connection.ReadLn;
  { Get the clients package info }
  Client := Pointer(AThread.Data);
  { Check to see if the clients name has been assigned yet }
  if Client.Name = 'Logging In' then
    { if not, assign the name and announce the client }
    Client.Name := Msg;
    BroadcastMessage('System', Msg + ' has just logged in.');
    { If name is set, then send the message } if Msg[1] <> '@' then
      { Not a system command }
      BroadcastMessage(Client.Name, Msg);
      { System command }
      Com := UpperCase(Trim(Copy(Msg, 2, Pos(':', Msg) - 2)));
      Msg := UpperCase(Trim(Copy(Msg, Pos(':', Msg) + 1, Length(Msg))));
      if Com = 'CLIENTS' then
        AThread.Connection.WriteLn('@' + 'clients:' +

Open in new window

.. note - procedure call custom Broadcast message proc upon client connection wich iterate through
all active client connections and send some message:
procedure TfrmMain.BroadcastMessage(WhoFrom, TheMessage: string);
  Count: Integer;
  List: TList;
    Msg: string;
  Msg := Trim(TheMessage);

  EMote := Trim(memEMotes.Lines.Values[Msg]);

  if WhoFrom <> 'System' then
    Msg := WhoFrom + ': ' + Msg;

  if EMote <> '' then
    Msg := Format(Trim(EMote), [WhoFrom]);

  List := tcpServer.Threads.LockList;
    for Count := 0 to List.Count - 1 do
(also part of that Indy demo project - available in Indy install folder)

Open in new window

bish wakimAuthor Commented:
Thank you. Iam going to test your solution very soon and come back to you.
Happy New year...
bish wakimAuthor Commented:
As a matter of fact  in my Indy version "AThread: TIdPeerThread"  is replaced by  "AContext: TIdContext "...
Here as my actual problem:
1. The Server (MyServer:TdTcpServer)  receives a message from client(MyClient:IdTcpClient) then returns  another message to the same
    client through the following event:
     procedure TFServer.MyserverExecute(AContext: TIdContext);
       var msgFromClient:string,msgToClient;
          msgFromClient := AContext.Connection.IOHandler.ReadLn;

2. the messageToClient is captured by MyClient through  TthreadComponent wich was activated inside the client application. In the client
    application   TIdTCpClient and TthreadComponent work together...
    procedure   ClientFormPage.IdThreadComponentRun(Sender: TIdThreadComponent)
      var msgFromServer:string;
        msgFromServer := MyClient1.IOHandler.ReadLn();
3. the DoSomeThing((msgFromServer) causes sometimes the Program to hang!!!!!
Please how can I solve this problem????
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Sinisa VukSoftware architectCommented:
Because Indy is blocking at transport layer, you need to be fast as possible in client/server events. Maybe can create separate threads which will consume received strings. So, your DoSomeThing must be a thread or as fast as can be.... Be sure that you exclude sending client on server side to send notice message back - this could also be a cause of hang.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bish wakimAuthor Commented:
Can you give a little code showing me how can I create a thread with Delphi and perform an action with it?
The DoSomthing that caused the hang was simply when I tried to open a TabControl page wich contains indeed a lot of graphics immediatley after I received an message from the server..
I manged to get red of this problem by going around ,However I don't think it is a good idea to avoid ugly situations without understanding what is really happening.
Thanks in advance
bish wakimAuthor Commented:
Thank you Sinisa...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.