In this part we are going to finish off the server side coding of our Chat Application. In the previous part - Server Side Chat Application with Borland Delphi/Indy - we discussed how the server actually carries out all its communication functions as well as how it interacts with the client application. We also defined and implemented all of the procedures and commands needed to run our custom communication protocol.
I’m not going to go in detail about how the code works, however, I will make sure to comment the code heavily, so that it makes sense when you read it.
Add the following three procedures in the implementation section:
class procedure TLog.AddMsg(const AMsg: String);
with Create(AMsg) do try
constructor TForm1.Create(AOwner: TComponent);
ts.ContextClass := TMyContext;
As I said in the previous tutorial, this code basically helps to keep the server working flawlessly by synchronizing messages that need to be displayed by components on the server form.
Next, double click on the connect button and add the following code:
procedure TForm1.btconnectClick(Sender: TObject);
memo1.Lines.Add('Server is now connected and ready to accept clients');
This code just gets the server to listen on the said port number as well as display a message.