Server Side Chat Application with Borland Delphi/Indy, concluded
(Page 1 of 4 )
This article picks up where last week's article on building a server side chat application left off. By the time you reach the end, you should have a fully functioning chat server.
A downloadable zip of the COMPLETE source code for the application is available
here.
Introduction
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.
Let’s continue…
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:
procedure TLog.DoSynchronize;
begin
form1.Memo1.Lines.Add(FMsg);
end;
class procedure TLog.AddMsg(const AMsg: String);
begin
with Create(AMsg) do try
Synchronize;
finally
Free;
end;
end;
constructor TForm1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ts.ContextClass := TMyContext;
end;
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);
begin
ts.DefaultPort:=strtoint(edport.Text);
ts.Active:=true;
memo1.Lines.Add('Server is now connected and ready to accept clients');
end;
This code just gets the server to listen on the said port number as well as display a message.
Next: Code for connecting clients >>
More Delphi-Kylix Articles
More By Jacques Noah