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 (5)


Indy Step by Step - Part1Go to Romeo Lefter's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Part 1: Overview of TCP/IP and indy
Product:
Delphi 4.x (or higher)
Category:
Internet / Web
Skill Level:
Scoring:
Last Update:
02/24/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Indy TCP/IP Internet Socket
Times Scored:
24
Visits:
14939
Uploader: Romeo Lefter
Company: Rombest Software
Reference: N/A
 
Question/Problem/Abstract:
Working with Indy
Answer:



  First was Winshoes. A set of "blocking sockets" components for delphi. I have worked with winshoes and I have created many programs. When delphi6 was released, the winshoes project was integrated in delphi, but with a new name (indy) and with a new sponsor (Nevrona design).

  In order to understand what you can do with indy I think a little introduction in TCP/IP is necessary.
  Characteristic for a TCP/Ip protocol are the following elements:
- IP address;
- Host Name;
- Port Number.
  In order to understand each element, I will show you a little example. Imagine that you are in a city. In the city there are Streets that are used for accessing different Buildings. Each building has an address and some buildings has a name (for example "Emire Stat Building"). In each building there are many Rooms, separated by Doors. This is a schematic representation of a city. Let's understand how can you go to a building in this city. First, you get a taxi. You say to the taxi driver to go to an address (in Ex: 23 Streed, no. 157). If you want to go to a "faimous" building, you can say to taxi driver the name of this building (i.e. Empire State Building) and the taxi driver will go to this building, because HE KNOWS WHERE THIS BUILDING IS. Oance you have arrived to your destination, you open one door of this building. If you want to go to a friend thats live there, you have to open your friend's door... All process is simply because we know it.
Now I'll say that this process is identical with TCP/IP. Let's see! In a TCP/IP network, all computers are connected like buildings in a city. The city streets are equivalent with TCP/IP network connections and the buildings are equivalent with computers connected in this network. Each computer has an unique address (like building's addresses). Some computers has Names, like important buildings in a city. When you type in your browser an address like http://www.google.com, the browser will go to a computer because he knows this computer address (in fact, the browser doesn't know the address, but you will be able to know later how a brouser find the address). The Port of a computer is equivalent to a door in a building. In fact, a port is a GATE to one service that this computer offer. In example, a computer can serve web pages. For that, you have to connect to port no. 80 of this computer and you will be able to access web pages that this computer offer. Some computers are FTP server. You can get files from this computers or you can put files to this computers. For that you have to connect to port no. 21. Examples can continue with other services like email, telnet etc.
  In general, this is all about TCP/IP. Is simple and efficient. As you can see, the entire internet infrastructure is based on this protocol and it's efficienty I think is demonstrated. Let's recapitulate and learn more about each element of the TCP/IP protocol

1. IP Address is a 4 byte unique number. Each byte is separated by a "." . In example 199.255.15.1 is a valid IP address.
2. The port is an integer number. With a port you can access a service offerd by a computer connected to a TCP/IP network. When you want to create a custom service, you have to use a port for this service. Usually ports numbers lowered than 1000 are considered reserved. But noone will suffer if you will use for a service a port no. lowered than this value.
3. Host Name is a name associated with a computer address. In example www.google.com is a HOST Name. This name is also unique. Let's return at our example. It's time to explain you how a browser "knows" the address when you enter a Host Name. First the browser interogate a DNS (Domain Name Service) computer about the host name you have entered and this computer replays with IP address of the host you have entered or with an error if this host is not valid. The process is little more complicated, but is not my intention for now to explain how DNS works.

   Here, our intro to TCP/Ip is finished. We will concentrate now on creating TCP/IP applications with Delphi using Indy components.
   But, first of all I'll explain you what "blocking" and "non-blocking" sockets are. In fact there are 2 programming models used in TCP/IP applications.
   NonBlocking means that the application will not be blocked when the application socket read/write data. This is efficient, because your application don't have to wait for a connection. Unfortunately, using this technique is little complicated to develop a protocol. If your protocol has many commands, your code will be very ininteligible.
   Blocking sockets are the opus concept. When a application that use a blocking socket sends or receives data, application events are "blocked". What that means? Simply. If the socket is implement in the application's main thread, the application's interface will not respond. In fact you will see a window that not "repaint" and not respond to your commands. Bored, isn't it?
   Maybe, now you will say: "Hei, man, why you continue with this indy? If my window will not respond to commands I have to deal with threads etc. I want to make my life easier." And my answer is: STAY CLOSE WITH INDY! Yes, indy uses blocked sockets, but is different! Now, in the indy package, is included an anti-freeze component thats prevent application window from "stop respond" moments. Many other  cool features, you will know later in this tutorial.

I have decided to not present here each indy components. If you have installed indy package, you will observe that there are many components divided in 3 categories:
- clients
- servers
- misc

In the clients Tab you have ready to use clients for all major protocole (pop3, http, ftp etc.). If you don't have any idea about how to use this protocols, read my previous tutorials about TCP/IP programming. There I have presented many common protocols. That tutorial refers to netMasters components, but reading it, you will understand how to use client components.
In the server Tab there are ready to build server components, also for all protocols. Using this server components is really simple but, in the final part I will present some implementations.
The misc Tab contains many many divers components. I will not insist here. You will see references to some misc components later.

The most important elements that I will presents here are: TIdTcpClient and TIdTcpServer components. And I will do that because this 2 components are the base stones of the indy architecture. All client components are inherited from TIdTcpClient and all server components are inherited from TIdTcpServer(there are some exception, but we will discuss later). Understanding this 2 components will make you a TCP/Ip expert. Belive me!





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Code examples
    crack m0nk3y (Nov 21 2003 8:13AM)

Im kinda new here but, does anyone ever show code, im mean i have been searching thru the site and am having a hard time finding any usefull code esp. on TCP, i KNOW what an IP address is i KNOW what a port is but i dont know the code for a simple TCP connection in delphi.
Respond

lame
    poo poo (Oct 3 2003 10:19AM)

hey mate guess what? its always good to include a link when you talk about something other wise there is no point! - http://www.nevrona.com/indy


Respond

I feel anoyed
    Paul Terlanen (Feb 28 2002 1:36PM)

where can I download the indy package?
Is comparable to Kudzu winshoes stuff?
Respond

RE: I feel anoyed
Romeo Lefter (Feb 28 2002 4:10PM)

http://www.nevrona.com/indy
Respond

RE: I feel anoyed
bula ionel (Jan 29 2003 10:09PM)

Forget anything else, use Indy...

Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
A. B. Talal
 
   














 







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