delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Indy Step by Step - Part 2.1Go to Romeo Lefter's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Part 2.1 Overviw of TIdTcpServer Component
Product:
Delphi 4.x (or higher)
Category:
Internet / Web
Skill Level:
Scoring:
Last Update:
02/19/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Indy TCP/IP Server Socket Internet Net
Times Scored:
20
Visits:
10864
Uploader: Romeo Lefter
Company: Rombest Software
Reference: N/A
 
Question/Problem/Abstract:
The Indy TCP/IP Server Componenent
Answer:



        Maybe you think we are starting now with the hard part. In fact this is true. We are starting with the hard part of indy. And, when we will build the client component, you will be amazed to know how easy is to build a client with indy.

For now, open a new project and put an IdTcpServer component on the form. IdTcpServer Component is located on the Indy Server tab (it is the first component in this tab). Now, set the following properties for this component:





Property NameProperty Value
ActiveTrue
DefaultPort1111
Greeting
   Text
Welcome to my server!


In fact, your first TCP server is almost complete. You haven't write any line of code and you have a working server. Amazing, isn't it? Let's test it! Run your program. A blank window will appear. For testing TCP servers, the most convenient method is to use the telnet program. If this is something new to you, read the Windows help and you will know what telnet is. For now, using telnet start a connection to localhost at port 1111. In short time you will receive the following message:
Welcome to my server!


When the telnet program connects to your server (as you maybe know your server works on port 1111; you have set up this property!) your server replays with the "Greeting message". A greeting is a special message that you receive when you are connected to a server. You can see greetings in real world. Just connect to a ftp port (telnet on port 21) and if is a greeting set, you will see it.

Now it's time to avance in our server example. We will implement our first command. Let's see how to do it! First I will describe how our server wilol work. First, when we will send to our server the command "responde" our server will replay with "Ok, I have responded". This is our first command implementation. For this set for the property CommandHandlersEnabled the true value and then double click on the CommandHandlers property. A Collection Editor will be open. Here click on AddNew button and a new item will apper. Here, set in Object inspector the following properties:




Property NameProperty Value
Commandresponde
ReplyNormal
   Text
Ok, I have responded!


Compile this project and test it with telnet program... After you connect, just enter the responde command and our server will reply with the "Ok, I have responded!" message. Amazing. All work was done without any line of code. Thanks to indy!

Before we will continue, we have to look in depth on the indy server internal architecture. Is a good step. After that you will understand all the indy server aspects. You must know that, each descendant of TIDTcpServer has the following behavior. First, when a client connects to it, a listener thread "intercept" this connection and then creates a thread that will handle all communication events. So, in the internal architecture there are 2 threads categories. First is a listener thread that "listen" and waits for a connection. When a client is connected, this thread transfer all the communication operations to another thread. This architecture is very cool because your client application will be able to connect any time, even if there are many parallel connections to the server. For this second category of thread you have 2 threading models. First is IdThreadDefault and second is IdThreadPool.
IdThreadDefault model is the standard threading model you are using in your applications. For each connection, a separate thread is created. When the connection is finished this thread is destroyed.
The second model, IdThreadPool, is designed for high performance servers. In a high "aglomerated" environments, creating and destroing threads can be a time consuming operation, so your server performance can be faulted by this operation. So, conform to this model, a number of threads you specify are created when your server starts. When a connection begins, a thread is allocated and when connection stops, the thread is not destroyed.
This is all Indy Thread Concepts. Simply and fast. Maybe you are now interested how can you select the thread model you wish. This is simply. On the "Indy Misc" tab, you have two components thats are designed for each thread model: TIdThreadMgrDefault and TIdThreadMgrPool. Drop one of this components on the form and then you can associate it to the TIdTcpServer component by filling the ThreadMgr property of the TIdTcpServer. If you don't have anything in this propery, the server threading model will be the default model. So, a TIdThreadMgrDefault will be created. If you want to use the pool thread model, you have to write in the PoolSize property of the TIdThreadMgrPool component the no. of threads that will be created when server starts.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
M. Shkolnik
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)