打印本文 打印本文 关闭窗口 关闭窗口
Introduction to Indy (转载)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3703  更新时间:2009/4/23 18:37:50  文章录入:mintao  责任编辑:mintao
sp;   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.

Chad works as a Senior Developer for Atozed Software.

上一页  [1] [2] [3] [4] [5] 

打印本文 打印本文 关闭窗口 关闭窗口