Indy 9
MClientThread
Hierarchy, Methods, Unit: IdTunnelMaster
Performs communication with service threads.
MClientThread = class(TThread)
Unit
IdTunnelMaster
Description
MClientThread is a TThread descendant that encapsulates the TIdTunnelMaster connection from the client to the service threads for the tunnel master.

MClientThread is used to store references to the TCP client connection to the tunnel server, and the master thread used by the tunnel server to handle client requests.

MClientThread communicates with the tunnel server by reading messages from the outbound TCP client, and constructs headers that encapsulate the message for the tunnel server. When the TCP client is no longer readable, the MClientThread will terminate.

MClientThread notifies the tunnel server when a service thread is disconnected, and allows the tunnel server to maintain the number of connected services.


MClientThread.Create
MClientThread
Constructor for the thread instance.
constructor Create(AMaster: TIdTunnelMaster);
Parameters
Master
Tunnel server context for the instance.
Description
Create is the constructor for the thread instance. Create initializes thread properties tot heir default values, including:

  • MasterParent - Server context in the Master parameter

  • FreeOnTerminate - True

  • DisconnectedOnRequest - False

  • SelfDisconnected - False

  • Locker - Constructed

Create adds the thread instance to MasterParent.Clients, and increments the TIdTunnelMaster number of services.

Create calls the inherited Create method to finalize construction of the thread instance.


MClientThread.Destroy
MClientThread
Frees the object instance.
destructor Destroy; override;
Description
Destroy is the destructor for the object instance, and is responsible for notifications to the MasterParent tunnel server that the thread will be freed. Destroy instructs the MasterParent to decrease the number of service threads for the tunnel server, and removes the connection from the client list.

When DisconnectedOnRequest is False, MClientThread will also generate and send a Tunnel Disconnect message to the tunnel server.

If the TCP client is still connected, the OutboundClient is disconnected and freed.

Destroy also calls the inherited Destroy method to finalize destruction of the object instance.


MClientThread.Execute
MClientThread
Implements the processing loop for the thread.
procedure Execute; override;
Description
Execute is a procedure used by MClientThread to implement the processing logic that allows the thread to communicate with service threads for the tunnel connection. Execute will listen for OutboundClient messages until the client requests disconnect, or until the thread is Terminated by either the server or the service thread.

Execute constructs the IdHeader.MsgType and the IdHeader.UserID for the OutboundClient message, and calls MasterParent.SendMsg to write the message to the tunnel connection.

When the thread is Terminated, Execute will set SelfDisconnected to True prior to exiting the method.


Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.