Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 4 - Building a Server Application in Delphi
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

Building a Server Application in Delphi
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2006-12-11

    Table of Contents:
  • Building a Server Application in Delphi
  • Application Support
  • Client-Server Applications with Delphi
  • Indy Servers
  • Building a Server application

  • 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


    Building a Server Application in Delphi - Indy Servers


    (Page 4 of 5 )

    We know from previous discussions that a server listens for client connections at a particular port and then responds to whatever requests are made by a client. Indy servers do exactly that and more. They set up a listener thread that is separate from the main application. This thread waits for connections from clients. When a client connects the server spawns a new thread to service that client. All the relevant events are executed within the context of that thread. So, what am I saying here? Basically, an indy server services many different clients simultaneously, in the same way that it would a single client.

    Indy offers three types of servers:

    • TidTCPServer- See below.
    •   TidUDPServer - Since UDP is connectionless, TIdUDPServer operates differently from TIdTCPServer. TIdUDPServer does not have any modes similar to TIdSimpleServer, but since UDP is connectionless, TIdUDPClient does have single use listening methods. TIdUDPServer when active creates a listening thread to listen for inbound UDP packets. For each UDP packet received, TIdUDPServer will fire the OnUDPRead event in the main thread, or in the context of the listening thread depending on the value of the ThreadedEvent property.
    •   TidSimpleServer - TIdSimpleServer is for creating single use servers. TIdSimpleServer is intended to service a single connection at a time.

    For the purposes of this article we are only going to discuss TidTCPServer:

    As the drawing above shows, Indy servers are designed around threads and operate to some extent as Unix servers do. While Unix servers work directly with the stack with virtually no abstraction layers, indy does the opposite and distances the programmer from the stack. This is because indy uses a high level of abstraction and internally implements many details that can be automatic and transparent.  This means that a lot of the code that you would have had to write is automatically done for you, simply by dropping a component on your Delphi form. While Unix forks a new process for each client connection, Indy simply creates a new thread for each new client. This gives indy all the advantages of processes and none of the disadvantages.

    Because indy uses threads, you can connect hundreds or in some cases thousands of clients to your server application at a time. The belief that your system will stop functioning if you have hundreds of threads running at the simultaneously is not borne out by what I see on my system every day. If you press Control+Alt+Del and have a look at how many threads are currently running on your system without making a dent in your system's performance, you will be surprised. 

    Limits on number of threads

    You will start to notice problems with your system when thread numbers reach around 900 or more. I've tested a custom chat application (created with Indy) with close to 990 clients connected and experienced problems on a Pentium III 900 MHz with 269 MB RAM. It is important to understand that the number of clients is not necessarily the same as concurrent threads. While each client is given an individual thread, a thread is only allocated while the client is connected. The problems associated with high volume server applications such as the chat server I mentioned before are addressed in Indy 10 by allowing other models in addition to threading of servers. Indy 10 is limited only by available memory to allocate sockets.

    More Delphi-Kylix Articles
    More By Leidago


       · This article shows you how to built a server application in Delphi.
     

    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 4 hosted by Hostway
    Stay green...Green IT