Indy Step by Step - Part1 Overview of TCP/IP and indy(5分)

  • 主题发起人 主题发起人 aq13
  • 开始时间 开始时间
A

aq13

Unregistered / Unconfirmed
GUEST, unregistred user!
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 cando
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 bydo
ors. 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 onedo
or of this building. If you want to go to a friend thats live there, you have to open your friend'sdo
or... 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 browserdo
esn'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 ado
or 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 applicationdo
n'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 youdo
n'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 willdo
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!
 
````****,my head will boooooooooom while i see English!
 
呵呵 我好不容易在delphi3000里找到的
我在漫漫的肯呢
有谁来翻译一下啊?
 

Similar threads

A
回复
0
查看
932
Andreas Hausladen
A
A
回复
0
查看
981
Andreas Hausladen
A
A
回复
0
查看
805
Andreas Hausladen
A
A
回复
0
查看
607
Andreas Hausladen
A
后退
顶部