Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 5 - Sever Side Chat Application with Borland D...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Sever Side Chat Application with Borland Delphi/Indy
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2005-12-26

    Table of Contents:
  • Sever Side Chat Application with Borland Delphi/Indy
  • The Code
  • Receiving messages: listnames, all, takeshot, name, file
  • Handling Commands: Listnames, all, takeshot
  • Handling commands: name, file

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Sever Side Chat Application with Borland Delphi/Indy - Handling commands: name, file


    (Page 5 of 5 )

    Command: name

    When this command is received, the server searches for the specified recipient on the list and passes the message on. Here’s how:

     

    procedure TMyContext.SendMsg(const ANick: String; const
    AMsg:String);
        var
            List: TList;
            Context: TMyContext;
            I: Integer;
        begin
    //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.

    Command: file

    procedure TMyContext.SendFile(const ANick,Fn:string);
        var
            List: TList;
            Context: TMyContext;
            I: Integer;
            FStream,fstream2: TFileStream;
    IdStream,idstream2: TIdStreamVCL;
    MStream: TMemoryStream;
        begin
           // lock the list
            List := FContextList.LockList;
            try
                for I := 0 to List.Count-1 do
                begin
    //search for the recipient name
                    Context := TMyContext(List[I]);
                    if Context.Nick = ANick then
                    begin
                        try
    //found it, now create the file
            FStream := TFileStream.Create(fn, fmOpenRead or
    fmShareDenyWrite);
           
            try
                IdStream := TIdStreamVCL.Create(fstream);
                try
    //send it!
                    Context.Connection.IOHandler.WriteLn
    ('pic@'+fn+';Sending file...');
                    Context.Connection.IOHandler.Write(IdStream, 0,
    True);
                    Context.Connection.IOHandler.WriteLn('done!');
                finally
                    IdStream.Free;
                end;
            finally
                FStream.Free;
            end;
    //if recipient name not found
           except
                        end;
                        Exit;
                    end;
                end;
            finally
                FContextList.UnlockList;
            end;
            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.

       · We hope you found this article enjoyable and educational. Please feel free to...
       · This has been really informative, and helped me redesign a freeware game servrer I...
       · For all those who sent me emails requesting to download the chat application. I've...
       · I downloaded the file and ran it under D7 and using Indy10.1.5[Error]...
     

    DELPHI-KYLIX ARTICLES

    - 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...
    - Using the Client Dataset in Two-Tiered Clien...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT