Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 4 - 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: Listnames, all, takeshot


    (Page 4 of 5 )

    Command:  Listnames

    When the server receives this command it collects all the nick names of the connected clients and sends it off to the requesting client. Here’s the procedure that handles this:

    procedure TMyContext.SendNicks;
        var
            List: TList;
            Context: TMyContext;
            I: Integer;
        begin
            List := FContextList.LockList;
            try
                if List.Count > 1 then
                begin
                    //Connection.IOHandler.WriteLn('Currently
    Connected:');
                    for I := 0 to List.Count-1 do
                    begin
                        Context := TMyContext(List[I]);
                        if Context <> Self then
    Connection.IOHandler.WriteLn('list@'+ Context.Nick);
                    end;
                  
                end else
                    Connection.IOHandler.WriteLn('list@No-one else is
    connected');
            finally
                FContextList.UnlockList;
            end;
        end;

    Command:  all

    When the server receives this command it sends the message to all connected clients. Here’s how:

    procedure TMycontext.BroadcastMsgAll(const ANick: String; const
    bmsg: String);
        var
            List: TList;
            Context: TMyContext;
            I: Integer;
        begin
            List := FContextList.LockList;
            try
                for I := 0 to List.Count-1 do
                begin
                    Context := TMyContext(List[I]);
                    if Context <> Self  then try
                        Context.Connection.IOHandler.WriteLn(ANick +
    '> ' + bmsg);
                    except end;
                end;
            finally
                FContextList.UnlockList;
            end;
        end;

    Command: takeshot:

    Next, I needed a procedure to convert bitmap images to jpeg format, because Delphi only works in the bitmap format. Also, when you send a picture over the Internet it is always best to use a format that does not take up a lot of space and that is Internet ‘friendly’.

    Procedure BmpToJpg(const Filename: String; Quality: TJPEGQualityRange=100);
     var Bmp: TBitmap;
     Jpg: TJpegImage;
     begin
     Bmp:=TBitmap.Create;
     Jpg:=TJpegImage.Create;
     try
     Bmp.LoadFromFile(Filename);
     Jpg.CompressionQuality:=Quality;
     Jpg.Assign(Bmp);
     Jpg.SaveToFile(ChangeFileExt(Filename, '.jpg' ));
     deletefile(filename);
     finally
     Jpg.Free;
     Bmp.Free;
     end;
     end;

    Here’s the procedure that actually takes the screenshot:

    procedure screenshot;
    var DCDesk: HDC; // hDC of Desktop
      bmp: TBitmap;
    begin
      {Create a bitmap}
      bmp := TBitmap.Create;
      
      {Set a bitmap sizes}
      bmp.Height := Screen.Height;
      bmp.Width := Screen.Width;
      {Get a desktop DC handle - handle of a display device context}
      DCDesk := GetWindowDC(GetDesktopWindow);
     
      {Copy to any canvas, here canvas of an image}
      BitBlt(bmp.Canvas.Handle, 0, 0, Screen.Width, Screen.Height,
             DCDesk, 0, 0, SRCCOPY);
      {Save the bitmap}
      bmp.SaveToFile('scrnshot.bmp');
       BMPtoJPG('scrnshot.bmp') ;
      {Release desktop DC handle}
      ReleaseDC(GetDesktopWindow, DCDesk);
      {Release a bitmap}
      bmp.Free;
    end;

    As the name suggests, the procedure takes a screenshot and saves it in a file called 'scrnshot.bmp'. This file will then be converted to jpeg format, before it is sent off to the requesting client. So, it is essential that this procedure is called before the bmptojpg procedure.

    More Delphi-Kylix Articles
    More By Jacques Noah


       · 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