Delphi-Kylix
  Home arrow Delphi-Kylix arrow Server Code for an Internet Access Control...
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

Server Code for an Internet Access Control Application
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-09-08

    Table of Contents:
  • Server Code for an Internet Access Control Application
  • Custom Procedures and Functions
  • Timing Procedure
  • Final Part of the Procedure

  • 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


    Server Code for an Internet Access Control Application


    (Page 1 of 4 )

    In the preceding article we dealt with the functional requirements of the server application as well as with the components that make up the server interface. In this article we will continue to build on the concepts that we discussed there and at the same time explore the code that runs the server application.

    The server code

    The code starts off with declaring some classes that we are going to use, including the definition for the context class, so let's kick off with them:


    TMyContext = class(TIdContext)

    public

    IP: String;

    Con: TDateTime;

    compname:string;

    end;


    You already have some background about the TidContext class, so I will not go into it here. The above code declares a descendant of the TidContext class as TMyContext and then declares some variables that will hold some of the information we will need. We collect this information when the client tries to connect to our server.

    The next class declaration deals with synchronization. Now, TidSync is needed here because it gives us the ability to pass parameters between synchronized methods:

    TLog = class(TIdSync)

    protected

    FMsg: String;

    procedure DoSynchronize; override;

    public

    constructor Create(const AMsg: String);

    class procedure AddMsg(const AMsg: String);

    end;


    Both the TLog and TMyContext objects are going to help in facilitating requests from the client machine. The Tlog object has an FMsg string variable, which will catch all communications that are going to come from a connected client. This variable will then be passed between the three methods of the TLog object. One of those methods updates the user interface. Both of these two classes separate the communication between the server and a client, away from the main VCL thread of the server. This ensures that the server can handle many client connections at the same time, because it does not actually handle the communication, it simply passes it on to the said objects for processing. The implementation of these two classes is very easy to understand:


    constructor TForm1.Create(AOwner: TComponent);

    begin

    inherited Create(AOwner);

    ts.ContextClass := TMyContext;

    end;


    The TMyContext class is created and inherits the properties and methods of the context class. You can then access a connected client's data by simply using the dot notation, as in "TMyContext.data." The DoSynchronization procedure simply updates the memo control of the form. Without this particular procedure, the application will try to update the control directly from the main thread. This will cause your application to crash:


    procedure TLog.DoSynchronize;

    begin

    form1.Memo1.Lines.Append(FMsg);

    end;


    The AddMsg procedure makes the client communication string available to the DoSynchronize procedure for processing:


    class procedure TLog.AddMsg(const AMsg: String);

    begin

    with Create(AMsg) do try

    Synchronize;

    finally

    Free;

    end;

    end;



    That's all there is for dealing with a potential future bottleneck situation. Because of the minimal communication between the server and client applications, I've not optimized this application as much as I otherwise would have.

    More Delphi-Kylix Articles
    More By David Web


     

    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