Sever Side Chat Application with Borland Delphi/Indy
This article will get you started on building a chat application based on the client/server model. It will be able to handle all of the basics found in chat applications like Microsoft Messenger and others.
//lock the list, so nothing is added while searching for the name
List := FContextList.LockList;
try
for I := 0 to List.Count-1 do
begin
//start the search
Context := TMyContext(List[I]);
if Context.Nick = ANick then
begin
try
//if found sent the message
Context.Connection.IOHandler.WriteLn(AMsg);
except
end;
Exit;
end;
end;
finally
FContextList.UnlockList;
end;
//if not found sent an error msg Self.Connection.IOHandler.WriteLn('The name you send the message to does not exist. Please click on ''Get list of Names on Chat'' button to get a full list of names.'); end;
This procedure searches for the recipient name and sends the message on. If it does not find the name on the list, it sends an error msg back to the sender.
Self.Connection.IOHandler.WriteLn(‘ The name you send the message to does not exist. Please click on ''Get list of Names on Chat'' button to get a full list of names.');
end;
This procedure basically sends the file to the intended recipient, like so:
Sender -->-----server---->----------->Recipient
As long as the recipient's name is on the list, the file will be sent to them.
This is not the world's most sophisticated chat application, but it can handle all of the basics found in chat applications like Microsoft Messenger and others. And it will be very easy to develop an image based chat by tweaking the procedures in this code.
Next
In the next installment we will finish off this part of the chat application.
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.