Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: idTCPClient & idTCPServer

www.cryer.info
Managed Newsgroup Archive

Re: idTCPClient & idTCPServer

Subject:Re: idTCPClient & idTCPServer
Posted by:"Martin James" (nospam@dial.pipex.com)
Date:Tue, 15 Aug 2006 15:19:02

Ian Groves wrote:
> Could you point me in the direction of a simple example.
>
> Many Thanks
>

Well, I do not have Indy 10 loaded at the moment but, looking at
idContext.pas and idtask.pas, it seems like you could use either method:

TidContext has:

   TIdContext = class;
   TIdContextClass = class of TIdContext;

This strongly suggests that the server has a 'contextClass' class
property that can be loaded with the class of a TidContext descendant.
This would allow the server to create your custom TidContext class,
(with its added 'password' and 'username' fields'), whenever it needed
to, eg. upon client connect.  I'm guessing that this is the 'proper' way
to meet your requirements, though Remy Lebeau is the real expert.  You
will probably have to typecast the passed TidContext to your descendant
class in the OnExecute.

Failing that, TidContext is descended from TidTask which has:

     FData: TObject;
..
     property Data: TObject read FData write FData;


This 'data' could be anything you want, eg simply:

TconnectionData=class(TObject)
   password:string;
   userName:string;
end;

In the OnConnect handler, you could create one of these and store it in
the 'data' field.  You could then typecast 'TidContext.data' back to
'TconnectionData'in OnExecute.  Note that Indy has, or had, a habit of
auto-freeing the 'data' object upon disconnect, (assuming it is
assigned).  This can be looked upon as useful or an OO design error <g>.
     I do not know whether this behaviour has been continued into Indy
10.  If not, you will have to free your 'data' object upon disconnection
to prevent leaks.

Rgds,
Martin

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive