Home arrow Delphi-Kylix arrow Server Code for an Internet Access Control Application

Server Code for an Internet Access Control Application

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.

Author Info:
By: David Web
Rating: 5 stars5 stars5 stars5 stars5 stars / 9
September 08, 2008
  1. · Server Code for an Internet Access Control Application
  2. · Custom Procedures and Functions
  3. · Timing Procedure
  4. · Final Part of the Procedure

print this article

Server Code for an Internet Access Control Application
(Page 1 of 4 )

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)


IP: String;

Con: TDateTime;



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)


FMsg: String;

procedure DoSynchronize; override;


constructor Create(const AMsg: String);

class procedure AddMsg(const AMsg: String);


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);


inherited Create(AOwner);

ts.ContextClass := TMyContext;


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;




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

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


with Create(AMsg) do try






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.

blog comments powered by Disqus

- 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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials