Home arrow Delphi-Kylix arrow Page 2 - Sever Side Chat Application with Borland Delphi/Indy
DELPHI-KYLIX

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.

Author Info:
By: Jacques Noah
Rating: 4 stars4 stars4 stars4 stars4 stars / 18
December 26, 2005
TABLE OF CONTENTS:
  1. · Sever Side Chat Application with Borland Delphi/Indy
  2. · The Code
  3. · Receiving messages: listnames, all, takeshot, name, file
  4. · Handling Commands: Listnames, all, takeshot
  5. · Handling commands: name, file

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Sever Side Chat Application with Borland Delphi/Indy - The Code
(Page 2 of 5 )

The first thing we need to do is create a class that will take the details  of every client that connects to the chat. For now we will only take three, the IP address(which will enable you to ban a client if necessary), Nick name and time/date of connection. We also define procedures to send messages, list connected names and files in the same class. Place the following code just below the ‘type’ heading of the form, making sure that it is above the form declaration.

 

TMyContext = class(TIdContext)
        public
            IP: String;
            Nick: String;
            Con: TDateTime;
           // compname:string;
            procedure SendMsg(const ANick: String; const AMsg:
String);
            procedure BroadcastMsg(const bmsg: String);
           procedure BroadcastMsgAll(const ANick: String; const
bmsg: String);
             procedure SendNicks;
           procedure SendFile(const ANick,Fn:string);
        end;

The code below is responsible for displaying messages. It frees up the main VCL thread. Without it, I found that the server system usually crashes.

 TLog = class(TIdSync)
        protected
            FMsg: String;
            procedure DoSynchronize; override;
        public
            constructor Create(const AMsg: String);
            class procedure AddMsg(const AMsg: String);
        end;

Add this line of code above the private section of the form:

constructor Create(AOwner: TComponent);override;

Also, add this under the ‘var’ section of the form:

 names:string;

and add in the implementation section:

uses jpeg;

Our communication protocol commands

listnames = request list of names of connected clients
all            = send message to all connected clients
takeshot  = takes a screenshot of any client
name       = sends a private message to named client
file          = sends a file


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 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials