The example we used in the previous article is fine, but it can never be a real world application. It is not thread safe, and it does not identify all connected clients clearly enough. In this final part of the series, we will modify the application we have created in the earlier parts so that it can be used in the real world.
class procedure TWriteResponse.AddResponse (const AResponse: String);
begin
with Create(AResponse) do try
Synchronize;
finally
Free;
end;
end;
constructor TForm1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
idTCPServer1.ContextClass := TClientinfo;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//idtcpserver1.Active:=false;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
idtcpserver1.Active:=false;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
idtcpserver1.Active:=true;
end;
end.
Conclusion
The code I use here is generic and can be applied to any client server scenario that meets the inherent requirements of a client server environment. So please use it as a template when implementing your own client server applications. I must once again thank the users at the Delphi newsgroups and also the writers of Indy in Depth who made some excellent reference material available.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.