Server Side Chat Application with Borland Delphi/Indy, concluded
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.
Server Side Chat Application with Borland Delphi/Indy, concluded - The heart of the application (Page 3 of 4 )
The next procedure is the heart of the server application. This is where all the messages and commands are dealt with. Go to the object inspector, this time double click on Onexecute and add the code below:
procedure TForm1.tsExecute(AContext: TIdContext);
var
msg,str,toname,filename,cmd,from,orsender:string;
FStream,fstream2: TFileStream;
IdStream,idstream2: TIdStreamVCL;
MStream: TMemoryStream;
idx,posi,col:integer;
Name1,Name2,Name3,MainStr: string;
begin
//get the message/command from the client
str:=acontext.Connection.IOHandler.ReadLn;
//split the message into three sections
posi:=pos('@',str);
cmd:=copy(str,1,posi-1);
//what is the command?
if cmd='listnames' then begin
//client asked for a list of connected client names
//send it!
TMyContext(AContext).SendNicks;
end
//client wants to sent a message to everybody
else if cmd='all' then begin
//cutt message up in three parts. Here you only need the senders name and message