Home arrow Delphi-Kylix arrow Page 4 - Server Side Chat Application with Borland Delphi/Indy, concluded
DELPHI-KYLIX

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.

Author Info:
By: Jacques Noah
Rating: 5 stars5 stars5 stars5 stars5 stars / 8
January 02, 2006
TABLE OF CONTENTS:
  1. · Server Side Chat Application with Borland Delphi/Indy, concluded
  2. · Code for connecting clients
  3. · The heart of the application
  4. · Code for leaving a chat

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Server Side Chat Application with Borland Delphi/Indy, concluded - Code for leaving a chat
(Page 4 of 4 )

The next bit of code deals with what happens when a client leaves the chat. Go to the object inspector, double click on OnDisconnect and add the code below:

procedure TForm1.tsDisconnect(AContext: TIdContext);
begin
//inform everybody that the client left the chat
TLog.AddMsg(TMyContext(AContext).Nick + ' Left the chat');
tmycontext(acontext).broadcastMsg(tmycontext(acontext).Nick + ' Left the chat');
end;

This last bit disconnects the server. Click anywhere on the form, go to the object inspector events tab, double click on Onclosequery and add the following code:

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
ts.Active:=false;
end;

Finally

Remember to add the following to the forms’ uses clause right at the top of the form but below ‘interface’: idcontext, idsync, idstreamvcl. Also, I’m using Indy version 10.0.52, so these units may not be available if you are using an older version, so try to update your Indy version.

Copy and paste both the code from the previous tutorial and this one, on one form in the order that I’ve shown them, and you should be ready to go.

That’s it! Now you have a fully functioning chat server. Next we are going to develop a client application that will allow people to connect to your server and chat! So stay tuned.


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.

blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials