Now the Client sends a command to the server to execute a function (This works good) now, in the same vein, i want a scenario where it returns something like 'Done' once the server has executed the program and it should show on the Label on the Client that everything is fine.
The simplest solution is to just call ReadLn() after WriteLn(), eg:
procedure TForm3.Button1Click(Sender: TObject);
begin
IdTCPClient1.Socket.WriteLn('SayHello');
Label1.Caption := IdTCPClient1.Socket.ReadLn;
end;
procedure SayHelloWorldMessageBox();
begin
ShowMessage('Hello World!');
end;
Note that
TIdTCPServer is multi-threaded, where the
OnExecute event is fired in worker threads, but
ShowMessage() is not a thread-safe function. It should never be called outside of the main UI thread. So, either use
TThread.Synchronize() or equivalent to call
ShowMessage() in the main UI thread, or else use a thread-safe function, such as
Windows.MessageBox().
AContext.Connection.IOHandler.Write('Done');
You should call
Socket.WriteLn() instead of
Socket.Write(), otherwise the client won't know when the string ends, unless you close the connection (which you are not doing) after sending the string.
Why does it not send a message from the Server to the Client to Display that "done",
It does (assuming
ShowMessage() does not deadlock/crash the calling thread), but the client you have shown is not coded to read the message.