Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Apr : Re: TIdTCPServer - threads, global data contd.

www.cryer.info
Managed Newsgroup Archive

Re: TIdTCPServer - threads, global data contd.

Subject:Re: TIdTCPServer - threads, global data contd.
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Mon, 17 Apr 2006 11:17:16

"Stephen Odgaard" <sso@cowi.dk> wrote in message
news:44417f5b@newsgroups.borland.com...

> Can I from the main thread get access to a list of connected
> clients (ie. with connected clients)

You did not say which version of Indy you are using.  In Indy 9,
TIdTCPServer has a Threads property for that purpose.  In Indy 10, it has a
Contexts property instead.  Both properties returns a TThreadList
(TIdThreadList in the latest Indy 10 snapshot) containing the currently
active connections.

> What initiatiates the OnExecute Event?

The internal thread that TIdTCPServer creates to manage a client connection.
All event handlers whose parameters provide access to a TIdThread (Indy 9)
or TIdContext (Indy 10) object (directly or indirectly) are triggered in the
context of that thread.

> How can I (eg. from the main thread) "provoke" the OnExecute Event
> handler of a given client to be executed in order to empty an outbound
info
> queue?

You cannot.  The OnExecute event is triggered automatically in a continuous
loop for the lifetime of the connection.  It will have to check the outbound
queue for pending data every time it is triggered.  All the main thread can
do is queue the desired data and wait for the OnExecute event to process it
later.

> How would you store data in relation to a specific client for use
> during later Execute handles (or another thread)?

TIdThread (Indy 9) and TIdContaxt (Indy 10) both have a Data property that
you can use for that.  Alternative, you can derive a new class with your own
properties/members, and then set the server's ThreadClass (Indy 9) or
ContextClass (Indy 10) property before activating the server.  In the event
handlers, you can cast the TIdThread/TIdContext pointers to your descendant
class type in order to directly access your custom items.


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive