Indy 9 | Content | Index | Reference

TIdIOHandlerSocket
Hierarchy, Properties, Methods, Events, See Also, Unit: IdIOHandlerSocket
Implements an input and output handler using socket handles.

    TIdIOHandlerSocket = class(TIdIOHandler)

Unit
IdIOHandlerSocket
Description
TIdIOHandlerSocket is a TIdIOHandler descendant that implements the framework used to perform input and output operations for Indy components using a socket handle as the source or destination.

TIdIOHandlerSocket implements abstract virtual methods inherited from TIdIOHandler that allow the handler to prepare and establish a connection to remote computer system, determine when the handler is ready to perform an IO operation, and perform the data transmission or receipt required for a component.

TIdIOHandlerSocket also exposes properties that allow acccess to the Binding for the socket connection, and use of the Nagle algorithm while performing IO operations.

TIdIOHandlerSocket.Binding
TIdIOHandlerSocket, See Also
Represents the socket handle used for a connection.

    property Binding: TIdSocketHandle;

Description
Binding is a read-only TIdSocketHandle property that represents the socket handle used for a connection to another computer system. Binding provides the mechanism used to determine when the handler is ready to perform its IO operation, and the physical conduit used in calls to the Send and Recv methods.

Use Open to insure that the Binding contains a valid socket handle data type.

Use ConnectClient to allocate the socket handle in Binding, and to spawn a TIdConnectThread that establishes the connection using Socks proxy and Timeout input parameters.

Use Close to insure that Binding is disconnected and freed.

TIdIOHandlerSocket.SocksInfo
TIdIOHandlerSocket
Implements support for proxied client connection in the IO handler.

    property SocksInfo: TIdSocksInfo;

Description
SocksInfo is a TIdSocksInfo property that provides support for proxied client connections for the system identified in Host and Port. SocksInfo is used when ConnectClient is called to establish the client connection to a remote computer system, and provides the actual Host address and port number used for the client connection for SOCKS version 4 and 5 support using the TIdSocksInfo.MakeSocksConnection method.

Reading the value of SocksInfo will insure that an object instance is created at runtime when a SocksInfo has not been assigned for the IO Handler.

Assigning SocksInfo for the IO Handler will insure that a previous TIdSocksInfo object instance, created at runtime or owned by a different form than the current object, is freed and released prior to assigning the new value.

SocksInfo will be freed in Destroy when the object instance has been created at runtime and theowner form has not been assigned.

TIdIOHandlerSocket.UseNagle
TIdIOHandlerSocket, See Also
Indicates the socket connection can use the Nagle algorithm.

    property UseNagle: boolean;

Description
UseNagle is a Boolean property that indicates if the socket connection in Binding can use the Nagle algorithm for send coalescing during output operations to the handle. The default value for UseNagle is True, as assigned in the Create constructor.

UseNagle is used in ConnectClient to determine if the Binding must set socket options that reflect the use of the algorithm during output operations.

TIdIOHandlerSocket.Close
TIdIOHandlerSocket, See Also
Closes and frees the socket handle used for input/output operations.

    procedure Close; override;

Description
Close is an overridden procedure that closes and frees the socket handle in Binding used for input and output operations. Use Open to insure that the Binding contains a valid socket handle data type. Use ConnectClient to allocate the socket handle in Binding, and to spawn a TIdConnectThread that establishes the connection using Socks proxy and Timeout input parameters.

TIdIOHandlerSocket.ConnectClient
TIdIOHandlerSocket, See Also
Establisheds a remote connection for the input/output handler.

    procedure ConnectClient(const AHost: string; const APort: Integer; const ABoundIP: string; const ABoundPort: Integer; const ABoundPortMin: Integer; const ABoundPortMax: Integer; const ATimeout: Integer = IdTimeoutDefault); override;

Parameters
const AHost: string
Address of the remote system for the client connection.
const APort: Integer
Port number for the remote connection.
const ABoundIP: string
IP Address bound to the local system.
const ABoundPort: Integer
Port number bound to the local computer.
const ABoundPortMin: Integer
Minimum bound port number for the local system.
const ABoundPortMax: Integer
Maximum bound port number for the local system.
const ATimeout: Integer = IdTimeoutDefault
Number of milliseconds to wait before a connection attempt fails. Default value is IdTimeoutDefault.
Description
ConnectClient is an overriden procedure in TIdIOHandlerSocket that implements the mechanism that allows an input/output handler to prepare and establish a client connection to a remote computer system using the input parameters.

ConnectClient calls the inherited ConnectClient method, allocates and Binds the socket handle in Binding using the values specified in ABoundIP, ABoundPort, ABoundPortMin, and ABoundPortMax.

If the value in AHost is a host name instead of an IP address, ConnectClient will trigger the OnStatus event to indicate that the address will be resolved prior to setting the peer address and port number for the physical connection in Binding.

ConnectClient will also set the socket options required for UseNage support.

ConnectClient also triggers the OnStatus event handler to indicate that the connection will be opened to the peer client connection prior to trying to open the connection with the timeout value specified in ATimeout.

ConnectClient uses a thread to connect to the remote computer system to allow use of a timeout value in Connect while respecting the operation of the TIdAntifreeze component when present. If the connection thread is terminated with an exception message, ConnectClient can raise an EIdConnectException exception with the exception messasge from the threaded connection. If the connection thread is terminated without an exception message prior to being Connected, ConnectClient can raise an EIdConnectTimeout exception.

Use Connected to detemine if the physical connection has been established after a call to ConnectClient.

TIdIOHandlerSocket.Connected
TIdIOHandlerSocket, See Also
Indicates if the physical connection for the handler is prepared and opened.

    function Connected: Boolean; override;

Return Value
Boolean - True when the handler connection is prepared and opened.
Description
Connected is an overriden Boolean function in TIdIOHandlerSocket that implements the method used to determine when the physical connection for the handler has been established, and is available for input/output operations.

Connected will indicate when the socket handle in Binding has been assigned and allocated.

Use Open to prepare the physical connection for the handler, and ConnectClient to establish the connection used by the handler.

TIdIOHandlerSocket.Create
TIdIOHandlerSocket, See Also
Constructor for the object instance.

    constructor Create(AOwner: TComponent); override;

Parameters
AOwner: TComponent
Owner of the object instance.
Description
Create is the Constructor for the object instance, and relies on the inherited Create constructor. Create also sets the default value of UseNagle to True, to indicate that use of the Nagle algorithm for send coalescing is allowed.

TIdIOHandlerSocket.Destroy
TIdIOHandlerSocket
Frees the object instance.

    destructor Destroy; override;

Description
Destroy is the destructor for the object instance. Destroy will free and release resources allocated to SocksInfo when it has been created at runtime without an owner form. Destroy calls the inherited Destroy method prior to exiting.

TIdIOHandlerSocket.Open
TIdIOHandlerSocket, See Also
Prepares an input/output source for the handler.

    procedure Open; override;

Description
Open is a overridden procedure that prepares an input/output source for the handler. Open calls the inherited Open method, and will insure that the socket handle in Binding for the physical connection has been assigned.

Use ConnectClient to establish the connection on the coket handle used by the handler.

TIdIOHandlerSocket.Readable
TIdIOHandlerSocket, See Also
Indicates that the socket handle is ready to read data.

    function Readable(AMSec: integer = IdTimeoutDefault): boolean; override;

Parameters
AMSec: integer = IdTimeoutDefault
Milliseconds to wait for the socket connection to become ready. Default value is IdTimeoutDefault.
Return Value
Boolean - True when ready.
Description
Readable is an overidden Boolean function that indicates if the socket handle in Binding is ready for input operations. Readable uses Binding to call the Readable method in the TIdSocketHandle object property with the value specified in AMSec.

Use Recv to perform the input operation using the socket handle in Binding.

TIdIOHandlerSocket.Recv
TIdIOHandlerSocket, See Also
Performs an input operation using a socket handle.

    function Recv(var ABuf; ALen: integer): integer; override;

Parameters
var ABuf
Destination buffer for values read from the connection.
ALen: integer
Number of bytes to read from the connection.
Return Value
Integer - Acutal number of bytes read from the connection.
Description
Recv is an overridden Integer function that performs an input operation using the socket handle in Binding. Recv calls the TIdSocketHandle.Recv method, using the input parameters ABuf and ALen, to perform the read operation.

ABuf is the destination for values read from the socket handle in Binding.

ALen indicates the number of bytes expected from the input operation.

The return value for the method is the actual number of bytes read using the socket handle.

TIdIOHandlerSocket.Send
TIdIOHandlerSocket, See Also
Performs an output operation using a socket handle.

    function Send(var ABuf; ALen: integer): integer; override;

Parameters
var ABuf
Values to be written on the connection.
ALen: integer
Number of bytes to be written on the connection.
Return Value
Integer - Acutal number of bytes written using the connection.
Description
Send is an overridden Integer function that performs an output operation using the socket handle in Binding. Send calls the TIdSocketHandle.Send method, using the input parameters ABuf and ALen, to perform the write operation.

ABuf is the buffer containing values to be written to the socket handle in Binding.

ALen indicates the number of bytes to be written in the output operation.

The return value for the method is the actual number of bytes written using the socket handle.

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