Home arrow Delphi-Kylix arrow Page 3 - Building a Server Application in Delphi
DELPHI-KYLIX

Building a Server Application in Delphi


In this article, the second part of a series, we will continue discussing how TCP/IP works in tandem with client server applications. Then, we are going to use this knowledge to implement the server part of an example client-server application with Delphi. We are also going to look at the various components that are available to create network applications.

Author Info:
By: Leidago
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
December 11, 2006
TABLE OF CONTENTS:
  1. · Building a Server Application in Delphi
  2. · Application Support
  3. · Client-Server Applications with Delphi
  4. · Indy Servers
  5. · Building a Server application

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building a Server Application in Delphi - Client-Server Applications with Delphi
(Page 3 of 5 )

So how can we write client server applications with Delphi? Well, Delphi 6+ comes with a group of Internet components called Indy, which implements various protocols and presents them neatly in the form of components. Since our primary aim is to create client-server applications, we are only going to focus on them. But I want to go into a bit of background on how Indy works, so that you have some knowledge of how to implement other components that you might want to use in the future.

Indy provides server and client components for almost all the protocols that you can find out there, anything from HTTP to SMTP. What I will do is to explain in general terms how indy implements or deals with servers and clients. I must point out, in the interest of fairness, that there are other free Internet components that you can use such as ICS, that can be used with Delphi. I choose to use Indy because it makes it easy to built Internet-based applications, and also because I've been using it for as long as I can remember without any major problems. The only problem you'll find is that there is not a whole lot of documentation around on how to use these components, particularly the newer versions.

Indy is different  from most other Internet components in the following ways:

  • Indy uses the blocking socket API.
  • Indy does not rely on events. Indy has events that can be used for informational purposes, but are not required.
  • Indy is designed for threads. Indy can be used without threads, however.
  • Indy is programmed using sequential programming.
  • Indy has a high level of abstraction. Most socket components do not effectively isolate the programmer from stack. Most socket components instead of isolating the user from the complexities of stack merely pass them on with a Delphi / C++ Builder wrapper.

Not all of the above points will make sense to you and I will not go into much detail about them in this article, but there are two terms mentioned that I want to explain. 

First I want to explain the term "blocking." What do we mean by blocking? Well it is a term that describes one of two methods of programming sockets under Windows, the other being non-blocking. Indy uses blocking socket calls. This means that indy waits until a operation is completed when it makes a call. For example, to connect a socket, you simply call the connect method and wait for it to return. If the connect method succeeds it will connect, if it does not, it will show an exception message.

Non-blocking calls on the other hand, handle things differently. For example when connecting a socket, the connect method will return BEFORE the socket is connected.  When the socket is connected, an event will occur. This requires that the communication logic be split up into many procedures, or that polling loops be used. So the blocking method makes things easier and straightforward.

Threads

The other term I want to explain is thread. A thread is a separate preemptive execution path. Using threads allows for different execution paths to be executed simultaneously.  Threads allow your  application to do more than one thing at a time.

Threading is available even if you only have one CPU. In reality only one thread is executing at a time, however the operating system preemptively interrupts the thread and switches to another one. Each thread is only executed for a very short time each pass. This allows for tens of thousands of "slices" to occur per second.

Because the switching is preemptive and unpredictable, to the software the threads appear to be executing in parallel, and software must take precautions about this. In multiple CPU systems threads can actually execute in parallel, however each CPU can in reality still only execute one thread at a time. So threading plays a major role in Indy, and it is one of the reasons why I think indy has the best and most practical Internet components available today.


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

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

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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