This example will also be covered in much less detail than the previous example as many of the concepts should now be understandable.
Source Code
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, IdBaseComponent, IdComponent, IdTCPServer;type
TformMain = class(TForm) IdTCPServer1: TIdTCPServer; procedure IdTCPServer1Execute(AThread: TIdPeerThread); private public end;var
formMain: TformMain;implementation
{R *.DFM}procedure TformMain.IdTCPServer1Execute(AThread: TIdPeerThread);
var
i: integer;begin
with AThread.Connection do begin WriteLn(''''Hello. DB Server ready.''''); i := StrToIntDef(ReadLn, 0); // Sleep is substituted for a long DB or other call Sleep(5000); WriteLn(IntToStr(i * 7)); Disconnect; end;end;
end.
Since the Execute event occurs within the context of a thread, the processing code can take as long as necessary. Each client will have its own thread and will not block other clients.
Testing
To test the DB Server, compile and run it. Telnet to it on port 6001. The server will respond with a welcome message. Enter a number. The server will "process" your request and return 5 seconds later with the answer.
Other Resources (Alphabetically)
- Borland Newsgroups - borland.public.delphi.internet.winsock and borland.public.cbuilder.internet at forums.borland.com
- RFCs - http://www.rfc-editor.org/
- Indy - http://www.nevrona.com/Indy/
More!
This article is an extract from the book Indy in Depth. Indy in Depth is an e-book which you can subscribe to and receive the complete book by e-mail. Also check out the Atozed Indy Portal at www.atozedsoftware.com
About the Author
Chad Z. Hower, a.k.a. "Kudzu" is the original author and project coordinator for Internet Direct (Indy). Indy consists of over 110 components and is included as a part of Delphi, Kylix and C Builder. Chad''''s background includes work in the employment, security, chemical, energy, trading, telecommunications, wireless, and insurance industries. Chad''''s area of specialty is TCP/IP networking and programming, inter-process communication, distributed computing, Internet protocols, and object-oriented programming. When not programming, he likes to cycle, kayak, hike, downhill ski, drive, and do just about anything outdoors. Chad, whose motto is "Programming is an art form that fights back", also posts free articles, programs, utilities and other oddities at Kudzu World at http://www.Hower.org/Kudzu/. Chad is an American ex-patriate who currently spends his summers in St. Petersburg, Russia and his winters in Limassol, Cyprus. Chad can be reached using this form.
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




