Indy 9
TIdTCPConnection
Hierarchy, Properties, Methods, Events, See Also, Unit: IdTCPConnection
Implements a TCP Connection component.
TIdTCPConnection = class(TIdComponent)
Unit
IdTCPConnection
Description
TIdTCPConnection encapsulates a complete Transmission Control Protocol (TCP) connection. TIdTCPConnection provides methods common to most client and/or server connections that do not require support a specific communications protocol or data representation. These method include buffered reading and writing using the TCP/IP protocol stack, and access to buffered values using ordinal data type and streams.

TIdTCPConnection publishes properties that allow configuration of the transport mechanism for the connection including ReadTimeout, RecvBufferSize, and SendBufferSize, ASCIIFilter, Intercept, IOHandler, and ASCIIFilter.

TIdTCPConnection also exposes event handlers that provide notifications of actions performed on the connection including OnDisconnected, OnWorkBegin, OnWork, and OnWorkEnd.

TIdTCPConnection is the ancestor class for TIdTCPClient and TIdTCPServer.


TIdTCPConnection.ASCIIFilter
TIdTCPConnection, See Also
Converts incoming characters to the US-ASCII character set.
property ASCIIFilter: boolean;
Description
ASCIIFilter is a Boolean property that indicates all data read from the protocol stack should have the high bit reset before storing the values in the Indy read buffer.

ASCIIFilter is used to insure that character data in the Indy buffer will contain values that can be represented using the US-ASCII character set (Decimal 0 through Decimal 127).

ASCIIFilter is used in ReadFromStack.


TIdTCPConnection.ClosedGracefully
TIdTCPConnection, See Also
Indicates that the connection has closed without data in the read buffer.
property ClosedGracefully: Boolean;
Description
ClosedGracefully is a read-only Boolean property that indicates if a connection has closed without data in the Indy read buffer, or if it was abruptly lost. ClosedGracefully is True when the connection calls Disconnect, and has meaning only when Connected is False.

CloseGracefully is updated in ReadFromStack when a the socket handle for the connection is ready for read operations.


TIdTCPConnection.Greeting
TIdTCPConnection, See Also
Represents a banner message received from connection to a protocol server.
property Greeting: TIdRFCReply;
Description
Greeting is a TIdRFCReply property that contains the banner message received during connection to a protocol server. Greeting contains one or more values indicating the initial response from the connection to the server.

Greeting is initialized in the Create constructor, and freed in Destroy. Greeting is normally updated by descendant classes, like TIdNNTP, TIdFTP, etc., that provide a welcome message during their overridden connect method.


TIdTCPConnection.InputBuffer
TIdTCPConnection, See Also
Represents the internal buffer for unhandled data read from the connection.
property InputBuffer: TIdManagedBuffer;
Description
InputBuffer is a read-only TIdBuffer property that represents the internal buffer used by Indy for unhandled data read for the connection. InputBuffer contains values read from the TCP/IP protocol stack using ReadFromStack.

Values in InputBuffer are affected by methods that extract data in various formats like CurrentReadBuffer, ReadStream, ReadLn, and ReadStrings. Most applications will use the methods that extract ordinal data types like ReadCardinal, ReadChar, ReadInteger, ReadSmallInt, and ReadString.

Note: InputBuffer is not the same as the internal buffer used for receive operations from the TCP/IP protocol stack, as indicated in RecvBufferSize.


TIdTCPConnection.Intercept
TIdTCPConnection
Allows intercept of read and write operations for the connection.
property Intercept: TIdConnectionIntercept;
Description
Intercept is a TIdConnectionIntercept property used to act as an intermediary between the protocol stack and a TIdTCPConnection. Intercept is used to perform operations that can include logging send and receive operations, or provide Secure Socket Layer (SSL) support for the connection.

The Intercept must be Enabled to allow Intercept actions to be performed.


TIdTCPConnection.IOHandler
TIdTCPConnection, See Also
Provides an abstract input/output source for send and receive operations.
property IOHandler: TIdIOHandler;
Description
IOHandler is a TIdIOHandler property that indicates the class to be used to provide input and output sources for the connection. IOHandler, and descendant classes, allow abstraction of send and receive operations using Socket connections, streams, or any input/output source where an IOHandler has been written. The default IOHandler in Indy is the socket-based TIdIOHandlerSocket.

IOHandler is used in methods that perform low-level read or write operations like ReadFromStack and WriteBuffer. IOHandler is also used in methods that access the connection status like CheckForDisconnect, Connected, DisconnectSocket, and Disconnect.

When accessing IOHandler in application code, always cast the IOHandler to the correct descendant class. This is needed to access any methods or properties in the descendant that cannot be represented in the ancestor class at runtime.


TIdTCPConnection.LastCmdResult
TIdTCPConnection, See Also
Represents response code and text values for the last command requested.
property LastCmdResult: TIdRFCReply;
Description
LastCmdResult is a read-only TIdRFCReply property that represents the complete response message received during execution of a command request on the client connection. LastCmdResult contains the response code, in numeric and text form, and one or more lines of text from the response message. LastCmdResult is updated when SendCmd sends the client request on the connection, and GetResponse is called to parse the numeric and text portions of the response message. LastCmdResult is cleared prior to parsing of the response values.

TIdTCPConnection.MaxLineAction
TIdTCPConnection, See Also
Indicates the action to be taken when the maximum line length is exceeded when reading data.
property MaxLineAction: TIdMaxLineAction;
Description
MaxLineAction is a TIdMaxLineAction property that indicates the action to be performed when the InputBuffer contains a line that exceeds the value assigned to MaxLineLength. MaxLineAction is used with MaxLineLength in ReadLn to determine if an EIdReadLnMaxLineLengthExceeded exception should be raised, or if the data is split into one or more lines when the conditions occurs. Note: MaxLineAction has significance only when MaxLineLength contains a non-zero value.

TIdTCPConnection.MaxLineLength
TIdTCPConnection, See Also
Maximum number of characters for line-oriented input methods.
property MaxLineLength: Integer;
Description
MaxLineLength is an Integer property that represents the maximum number of characters that can be read using a single call to ReadLn or InputLn method call. MaxLineLength is intended to protect TIdTCPConnection and descendants from Denial of Service attacks that might result from unchecked memory usage. The default value for MaxLineLength is IdMaxLineLengthDefault, as assigned in the Create constructor.

MaxLineLength is used in ReadLn and InputLn when the maximum line length argument to the method is -1 indicating that the property value should be used.


TIdTCPConnection.OnDisconnected
TIdTCPConnection, See Also
Represents the event handler for peer disconnect events.
property OnDisconnected: TNotifyEvent;
Parameters
Sender
Connection triggering the event.
Description
OnDisconnected is the TNotifyEvent event handler used to respond to event notifications when the peer is disconnected. OnDisconnected is triggered when the Disconnect method is used to close the socket connection.

An application must assign a procedure to OnDisconnected to allow a response to the event notification.


TIdTCPConnection.OnWork
TIdTCPConnection, See Also
Work event handler for buffered read and write operations.
property OnWork;
Parameters
AWorkCount
Bytes affected by this operation.
AWorkMode
Operation being performed.
Sender
Owner of this instance.
Description
OnWork is the event handler for the event TWorkEvent. OnWork is used in conjunction with DoWork to notify Indy components and classes when buffered read or write operations are invoked. OnWork is generally used to control the update of progress indicators or GUI components.

AWorkMode indicates the operation performed and the notification sent to OnWork. AWorkMode can be contain one of the following values:

  • wmRead - The component is reading data from the peer.

  • wmWrite - The component is sending data to the peer.

AWorkCount indicates the number of bytes affected by the operation sent to OnWork.

The event TWorkEvent is implemented in IdComponent.pas.

TIdTCPConnection publishes the OnWork event. OnWork is not published in the ancestor class TIdComponent.


TIdTCPConnection.OnWorkBegin
TIdTCPConnection, See Also
WorkBegin event handler for starting read or write buffering.
property OnWorkBegin;
Parameters
AWorkCountMax
Maximum number of bytes expected.
AWorkMode
Operation being performed.
Sender
Owner of this instance.
Description
OnWorkBegin is an event of type TWorkBeginEvent as implemented in TIdComponent. OnWorkBegin is used in conjunction with BeginWork to notify Indy components and classes when buffered read or write operations are initiated. OnWorkBegin is generally used to control the update of progress indicators or GUI components.

AWorkMode indicates the operation performed and the notification sent to OnWorkBegin. AWorkMode can contain one of the following values:

  • wmRead - The component is reading data from the peer.

  • wmWrite - The component is sending data to the peer.

AWorkCountMax indicates the maximum number of bytes expected for the operation sent to OnWorkBegin, or 0 when the number of bytes not known.

The event TWorkEvent is implemented in IdComponent.pas.

TIdTCPConnection publishes the OnWorkBegin event. OnWork is not published in the ancestor class TIdComponent.


TIdTCPConnection.OnWorkEnd
TIdTCPConnection, See Also
WorkEnd event handler triggered when stopping read and write buffering operations.
property OnWorkEnd;
Parameters
AWorkCount
Bytes affected by this operation.
AWorkMode
Operation being performed.
Sender
Owner of this instance.
Description
OnWorkEnd is an event of type TWorkEndEvent as implemented in TIdComponent. OnWorkEnd is used in conjunction with EndWork to notify Indy components and classes when buffered read or write operations are concluded.

AWorkMode indicates the operation performed and the notification sent to OnWork. AWorkMode can contain one of the following values:

  • wmRead - The component is reading data from the peer.

  • wmWrite - The component is sending data to the peer.

AWorkCount contains the number of bytes affected by the operation.

TIdTCPConnection publishes the OnWorkEnd event. OnWorkEnd is not published in the ancestor class TIdComponent.


TIdTCPConnection.ReadLnSplit
TIdTCPConnection, See Also
Indicates that a read from the Input buffer has been split at the maximum line length.
property ReadLnSplit: Boolean;
Description
ReadLnSplit is a read-only Boolean property that indicates if data read from InputBuffer has been split into additional lines due to the line length limitations. ReadLnSplit will contain True when ReadLn encounters a line in InputBuffer having a length that exceeds the value in MaxLineLength, and MaxLineAction contains maSplit. ReadLn will extract the number of characters indicated in MaxLineLength, and allow subsequent operations to handle the remaining data in InputBuffer.

TIdTCPConnection.ReadLnTimedOut
TIdTCPConnection, See Also
Indicates that a timeout occurred in ReadLn.
property ReadLnTimedOut: Boolean;
Description
ReadLnTimedOut is a read-only Boolean property that indicates when a timeout has occurred in the ReadLn method.

ReadLnTimedOut is updated in the ReadLn method, and is set to True when the return value for ReadFromStack is 0.


TIdTCPConnection.ReadTimeout
TIdTCPConnection, See Also
Indicates the milliseconds to wait for a readable connection.
property ReadTimeout: Integer;
Description
ReadTimeout is an Integer property that indicates the number of milliseconds that the connection should wait for the peer connection to become readable using the protocol stack.

ReadTimeout is used in ReadFromStack.


TIdTCPConnection.RecvBufferSize
TIdTCPConnection
Indicates the current size of the default receive buffer for the connection.
property RecvBufferSize: Integer;
Description
RecvBufferSize is an Integer property that represents the number of bytes currently allocated to the default receive buffer used for the connection.

The default value for RecvBufferSize is 8192 bytes, and is asssigned in Create.


TIdTCPConnection.SendBufferSize
TIdTCPConnection, See Also
Indicates the maximum buffer size to use for writing to the connection.
property SendBufferSize: Integer;
Description
SendBufferSize is an Integer property that indicates the maximum number of bytes that can be allocated when writing data to the connection. The default value for SendBufferSize is 32768.

SendBufferSize is used in WriteStream to determine if the number of "chunks" needed to Write the TStream contents. When the stream is larger that SendBufferSize, multiple "chunks" will be used.


TIdTCPConnection.Socket
TIdTCPConnection, See Also
Provides access to the TIdIOHandlerSocket IOHandler for the connection.
property Socket: TIdIOHandlerSocket;
Description
Socket is a read-only TIdIOHandlerSocket property. Socket is a convenience property that provides access to the propeties and methods of the TIdIOHandlerSocket handler assigned for the socket connection. For example, the following statement groups are equivalent:

      AConnection.Socket.Binding.IP := sIPAddress;
      AConnection.Socket.Binding.Port := iPort;
      sPeer := AConnection.Socket.Binding.PeerIP;
      iPeer := AConnection.Socket.Binding.PeerPort;
      

      TIdIOHandlerSocket(AConnection.IOHandler).Binding.IP := sIPAddress;
      TIdIOHandlerSocket(AConnection.IOHandler).Binding.Port := iPort;
      sPeer := TIdIOHandlerSocket(AConnection.IOHandler).Binding.PeerIP;
      iPeer := TIdIOHandlerSocket(AConnection.IOHandler).Binding.PeerPort;

Socket will contain the value Nil when the assigned IOHandler is not a TIdIOHandlerSocket class instance.


TIdTCPConnection.AllData
TIdTCPConnection, See Also
Retrieves all data from a connection.
function AllData: string; virtual;
Description
AllData is a String function that retrieves all data from a peer connection until the connection is closed. AllData triggers OnWorkBegin event handler, reads values from CurrentReadBuffer, and triggers the OnWorkEnd event handler as a single operation.

Note: Do not use AllData unless the protocol you are using works in this manner. Protocols which support AllData include Finger, Quote of the Day, and WhoIs.


TIdTCPConnection.CancelWriteBuffer
TIdTCPConnection, See Also
Stops write buffering in Indy.
procedure CancelWriteBuffer;
Description
CancelWriteBuffer ends use of the internal write buffering mechanism in Indy without transmitting the data in the write buffer. CancelWriteBuffer calls ClearWriteBuffer to remove the contents of the write buffer, and calls CloseWriteBuffer to disable continued use of the write buffer during output operations.

TIdTCPConnection.Capture
TIdTCPConnection, See Also
Reads data from the connection into the specified object.
procedure Capture(ADest: TStream; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStream; out VLineCount: Integer; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStrings; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStrings; out VLineCount: Integer; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
Parameters
ADest: TStream
Storage for the captured data values.
const ADelim: string = '.'
Delimiter for captured data values. Default value is '.'.
const AIsRFCMessage: Boolean = True
Captured data is an RFC 822 message. Default value is True.
Description
Capture is a procedure used to read data from the connection into the destination specified by ADest. ADest must be an instance of either a TStrings descendant or a TStream descendant, or an EIdObjectTypeNotSupported exception with the constant message RSObjectTypeNotSupported will be raised when data is written to ADest.

ADelim is the delimiter used to determine if all data has been read from the connection. ADelim will appear in a line with no other data when all data has been captured. The default delimiter is '.', as used in most RFC-compliant protocols.

AIsRFCMessage indicates that Capture is reading an RFC 822 message where a line may start with the characters '..'. Capture will convert this character sequence to a single '.' character. A single '.' character in a line indicates the end of the RFC 822 message.

Capture triggers the OnWorkBegin event handler with wmRead mode before reading data from the connection. Capture calls ReadLn to retrieve data from the connection until the delimiter specified in ADelim is received. Each line is written to the ADest object reference upon receipt. Capture triggers the OnWorkEnd event handler with wmRead mode when all data has been captured from the connection.


TIdTCPConnection.Capture
TIdTCPConnection, See Also
Reads data from the connection into the specified object.
procedure Capture(ADest: TStream; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStream; out VLineCount: Integer; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStrings; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStrings; out VLineCount: Integer; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
Parameters
ADest: TStream
Storage for the captured data values.
const ADelim: string = '.'
Delimiter for captured data values. Default value is '.'.
const AIsRFCMessage: Boolean = True
Captured data is an RFC 822 message. Default value is True.
Description
Capture is a procedure used to read data from the connection into the destination specified by ADest. ADest must be an instance of either a TStrings descendant or a TStream descendant, or an EIdObjectTypeNotSupported exception with the constant message RSObjectTypeNotSupported will be raised when data is written to ADest.

ADelim is the delimiter used to determine if all data has been read from the connection. ADelim will appear in a line with no other data when all data has been captured. The default delimiter is '.', as used in most RFC-compliant protocols.

AIsRFCMessage indicates that Capture is reading an RFC 822 message where a line may start with the characters '..'. Capture will convert this character sequence to a single '.' character. A single '.' character in a line indicates the end of the RFC 822 message.

Capture triggers the OnWorkBegin event handler with wmRead mode before reading data from the connection. Capture calls ReadLn to retrieve data from the connection until the delimiter specified in ADelim is received. Each line is written to the ADest object reference upon receipt. Capture triggers the OnWorkEnd event handler with wmRead mode when all data has been captured from the connection.


TIdTCPConnection.Capture
TIdTCPConnection, See Also
Reads data from the connection into the specified object.
procedure Capture(ADest: TStream; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStream; out VLineCount: Integer; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStrings; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStrings; out VLineCount: Integer; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
Parameters
ADest: TStream
Storage for the captured data values.
const ADelim: string = '.'
Delimiter for captured data values. Default value is '.'.
const AIsRFCMessage: Boolean = True
Captured data is an RFC 822 message. Default value is True.
Description
Capture is a procedure used to read data from the connection into the destination specified by ADest. ADest must be an instance of either a TStrings descendant or a TStream descendant, or an EIdObjectTypeNotSupported exception with the constant message RSObjectTypeNotSupported will be raised when data is written to ADest.

ADelim is the delimiter used to determine if all data has been read from the connection. ADelim will appear in a line with no other data when all data has been captured. The default delimiter is '.', as used in most RFC-compliant protocols.

AIsRFCMessage indicates that Capture is reading an RFC 822 message where a line may start with the characters '..'. Capture will convert this character sequence to a single '.' character. A single '.' character in a line indicates the end of the RFC 822 message.

Capture triggers the OnWorkBegin event handler with wmRead mode before reading data from the connection. Capture calls ReadLn to retrieve data from the connection until the delimiter specified in ADelim is received. Each line is written to the ADest object reference upon receipt. Capture triggers the OnWorkEnd event handler with wmRead mode when all data has been captured from the connection.


TIdTCPConnection.Capture
TIdTCPConnection, See Also
Reads data from the connection into the specified object.
procedure Capture(ADest: TStream; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStream; out VLineCount: Integer; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStrings; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
procedure Capture(ADest: TStrings; out VLineCount: Integer; const ADelim: string = '.'; const AIsRFCMessage: Boolean = True); overload;
Parameters
ADest: TStream
Storage for the captured data values.
const ADelim: string = '.'
Delimiter for captured data values. Default value is '.'.
const AIsRFCMessage: Boolean = True
Captured data is an RFC 822 message. Default value is True.
Description
Capture is a procedure used to read data from the connection into the destination specified by ADest. ADest must be an instance of either a TStrings descendant or a TStream descendant, or an EIdObjectTypeNotSupported exception with the constant message RSObjectTypeNotSupported will be raised when data is written to ADest.

ADelim is the delimiter used to determine if all data has been read from the connection. ADelim will appear in a line with no other data when all data has been captured. The default delimiter is '.', as used in most RFC-compliant protocols.

AIsRFCMessage indicates that Capture is reading an RFC 822 message where a line may start with the characters '..'. Capture will convert this character sequence to a single '.' character. A single '.' character in a line indicates the end of the RFC 822 message.

Capture triggers the OnWorkBegin event handler with wmRead mode before reading data from the connection. Capture calls ReadLn to retrieve data from the connection until the delimiter specified in ADelim is received. Each line is written to the ADest object reference upon receipt. Capture triggers the OnWorkEnd event handler with wmRead mode when all data has been captured from the connection.


TIdTCPConnection.CheckForDisconnect
TIdTCPConnection, See Also
Determines if the peer has been disconnected.
procedure CheckForDisconnect(const ARaiseExceptionIfDisconnected: boolean = true; const AIgnoreBuffer: boolean = false); virtual;
Parameters
const ARaiseExceptionIfDisconnected: boolean = true
Raise an exception when the connection is closed. Default value is True.
const AIgnoreBuffer: boolean = false
Disregards the read buffer size. Default value is False.
Description
CheckForDisconnect is a procedure used to determine if a connection has been closed by either the server or the client. ClosedGracefully is used to determine if a connection has ClosedGracefully, or if the IOHandler no longer contains an allocated socket handle for the connection. If neither condition exists for the connection, no additional processing is performed and the method returns.

When the connection has been ClosedGracefully, and the IOHandlerSocket.Binding has an allocated socket handle, then DisconnectSocket is called to force the socket handle to be deallocated.

Under some conditions, CheckForDisconnect can raise an EIdConnClosedGracefully exception. The exception can occur when the Indy Read buffer is empty or should be ignored (as indicated in AIgnoreBuffer), and ARaiseExceptionIfDisconnected indicates that the exception is desired.

For a Server connection, this indicates that the client has disconnected the socket connection normally. The Exception is used to notify Server handling code. The exception is normal and will only happen from within the IDE, not while your program is running as an EXE. If you do not want to see this, add the EIdConnClosedGracefully exception or EIdSilentException to the IDE options as exceptions not to break on. From the IDE, press F9 and Indy will catch and handle the exception.

For a Client connection, this indicates that the server has disconnected the socket connection normally, but the client has attempted to read or write using the closed connection. You should trap this error using a try..except block.

Please see the FAQ at http://www.nevrona.com/Indy/FAQ.html for additional information.


TIdTCPConnection.CheckForGracefulDisconnect
TIdTCPConnection, See Also
Determines if the peer has been gracefully disconnected.
procedure CheckForGracefulDisconnect(const ARaiseExceptionIfDisconnected: Boolean = True); virtual;
Parameters
const ARaiseExceptionIfDisconnected: Boolean = True
Raise an exception when the connection is closed. Default value is True.
Description
CheckForGracefulDisconnect is a procedure used to determine if the connection has been closed gracefully. CheckForGracefulDisconnect calls ReadFromStack using the value in ARaiseExceptionIfDisconnected and a 1 millisecond timeout to verify that the socket handle is ready to perform a read operation.

ReadFromStack updates the ClosedGracefully property and performs exception handling as specified in ARaiseExceptionIfDisconnected.


TIdTCPConnection.CheckResponse
TIdTCPConnection, See Also
Checks for a valid response in an array of allowable responses.
function CheckResponse(const AResponse: SmallInt; const AAllowedResponses: array of SmallInt): SmallInt; virtual;
Parameters
const AResponse: SmallInt
Response number to examine.
const AAllowedResponses: array of SmallInt
Array of response numbers allowed.
Return Value
SmallInt - Response number encountered, or zero on error.
Description
CheckResponse is a SmallInt function used to check for the existence of the response number in AResponse in the array of allowable responses AAllowedResponses. If CheckResponse examines all allowable response and does not find AResponse, RaiseExceptionForLastCmdResult is called.

TIdTCPConnection.ClearWriteBuffer
TIdTCPConnection, See Also, Example
Clears the Indy write buffer.
procedure ClearWriteBuffer;
Description
The ClearWriteBuffer method clears the data which has accumulated since the OpenWriteBuffer without sending it. This does not stop write buffering. Only CloseWriteBuffer and CancelWriteBuffer stop write buffering.

TIdTCPConnection.CloseWriteBuffer
TIdTCPConnection, See Also
Stops write buffering.
procedure CloseWriteBuffer;
Description
CloseWriteBuffer is a procedure that forces all data written to the Indy write buffer since a call to OpenWriteBuffer to be sent to the peer connection. CloseWriteBuffer disables further writes to the Indy write buffer.

TIdTCPConnection.Connected
TIdTCPConnection, See Also
Indicates if the peer connection is open and active.
function Connected: Boolean; virtual;
Description
Connected is a Boolean function used to indicate when the connection to the peer is open and active. Connected calls CheckForDisconnect to to determine if the connection was closed normally or abruptly terminated, and returns true when the IOHandler indicates that it is Connected.

TIdTCPConnection.Create
TIdTCPConnection
Constructor for the object instance.
constructor Create(AOwner: TComponent); override;
Parameters
AOwner: TComponent
Owner of the object instance.
Description
Create is the constructor for a new TIdTCPConnection object instance. Create initializes the following to their default values:

  • CmdResultDetails - TStringList Holds command responses.

  • RecvBuffer - protected TIdBuffer Used to receive data from the TCP stack.

  • RecvBufferSize - Integer Size of RecvBuffer (default value is 8192).

  • SendBufferSize - Integer Size of SendBuffer (default value is 8192).

  • Buffer - protected TIdBuffer Used to internally buffer Indy reads and writes.

Descendant classes should override this constructor to set default values such as Port, and other protocol specific options.


TIdTCPConnection.CurrentReadBuffer
TIdTCPConnection, See Also
Updates the Indy buffer with data from the protocol stack.
function CurrentReadBuffer: string;
Return Value
String - Contents of the Indy buffer.
Description
CurrentReadBuffer is a String function that reads any pending data from the protocol stack for a Connected session, and adds the data to the Indy read buffer.

The return value includes all data in the Indy buffer up to size of the internal buffer. Result may also be '' (empty string) if no data is present in the internal Indy buffer.


TIdTCPConnection.Destroy
TIdTCPConnection, See Also
Frees the object instance.
destructor Destroy; override;
Description
Destroy is the destructor for the object instance. Destroy is responsible for freeing and releasing the resources allocated to properties in the Create constructor. Destroy calls DisconnectSocket insure that the physical connection to the peer is closed. Destroy relies on the inherited Destroy method to complete destruction of the object instance.

TIdTCPConnection.Disconnect
TIdTCPConnection, See Also
Disconnects the peer connection.
procedure Disconnect; virtual;
Description
Disconnect is used to disconnect from the current peer connection. Many descendant components override this method to provide termination commands required by various protocols. If you simply need to close a connection, you probably should call the DisconnectSocket method.

Disconnect triggers a hsDisconnecting status notification message prior to calling DisconnectSocket. When needed, Disconnect also frees the IOHandler. Finally, Disconnect triggers the OnDisconnected event handler and a hsDisconnected status notification message.


TIdTCPConnection.DisconnectSocket
TIdTCPConnection, See Also
Closes the socket binding for the connection.
procedure DisconnectSocket; virtual;
Description
DisconnectSocket is a procedure used to close the socket binding for the connection. Unlike the Disconnect method, DisconnectSocket is not overridden by descendant classes to provide termination sequences required for a particular protocol.

DisconnectSocket is used when an error has occurred in a protocol handler and a guaranteed disconnect is needed.


TIdTCPConnection.FlushWriteBuffer
TIdTCPConnection, See Also
Writes buffered data, and clears the write buffer in Indy.
procedure FlushWriteBuffer(const AByteCount: Integer = -1);
Parameters
ABytes
Threshold value for number of bytes to flush. Default value is -1.
Description
FlushWriteBuffer transmits all data which has been buffered since the call to the OpenWriteBuffer method to be sent to the peer. Buffered data is cleared after being sent to the peer connection. Write buffering remains active after the FlushWriteBuffer method is completed. Only CloseWriteBuffer and CancelWriteBuffer can be used to stop write buffering after a call to OpenWriteBuffer.

ABytes indicates the threshold value for the number of bytes that should be removed from the Indy buffer and sent to the peer socket connection. The default value (-1) forces all data in the Indy buffer to be written to the peer, and the write buffer is cleared using ClearWriteBuffer. This is also the case when the buffer is smaller than the threshold value in ABytes. Otherwise, the number of bytes in ABytes is removed from the Indy buffer and sent to the peer.


TIdTCPConnection.GetInternalResponse
TIdTCPConnection, See Also
Impelements reading of response detail lines from a peer connection.
procedure GetInternalResponse;
Description
GetInternalResponse is a public procedure used to implement the processing required for the GetResponse method. GetInternalResponse clears the values in CmdResultDetails, and reads one or more reponse lines from a peer connection using ReadLnWait.

The initial response line is expected to contain the 3-digit response code and text. Additional response lines are read when the initial response is a continuation response line, and continues until the terminal response or a blank line is received. All response lines are added to LastCmdResult.


TIdTCPConnection.GetResponse
TIdTCPConnection, See Also
Retrieves one or more response messages from the connection.
function GetResponse(const AAllowedResponses: array of SmallInt): SmallInt; virtual; overload;
function GetResponse(const AAllowedResponse: SmallInt): SmallInt; overload;
Parameters
const AAllowedResponses: array of SmallInt
Array of Integer response number permitted.
const AAllowedResponse: SmallInt
An Integer response number expected.
Return Value
SmallInt - The numeric response number.
Description
GetResponse is a overloaded SmallInt function that waits for a response message from the peer (such as greetings from a computer or command replies) and returns the numerical response number for the reply. GetResponse reads response lines from the connection, including continuation response messages until the terminal response message is received. All response messages are added to to the LastCmdResult property.

Use LastCmdResult to access the full text or numeric response number for the most recent response message, or multiple response messages.

GetResponse sets ResultNo to the three-digit numeric value from the most recent response message in LastCmdResult.

Finally, GetResponse calls CheckResponse using the values in ResultNo and AAllowedResponses to determine if the numeric response code is one of the numeric values allowed for the protocol action.


TIdTCPConnection.GetResponse
TIdTCPConnection, See Also
Retrieves one or more response messages from the connection.
function GetResponse(const AAllowedResponses: array of SmallInt): SmallInt; virtual; overload;
function GetResponse(const AAllowedResponse: SmallInt): SmallInt; overload;
Parameters
const AAllowedResponses: array of SmallInt
Array of Integer response number permitted.
const AAllowedResponse: SmallInt
An Integer response number expected.
Return Value
SmallInt - The numeric response number.
Description
GetResponse is a overloaded SmallInt function that waits for a response message from the peer (such as greetings from a computer or command replies) and returns the numerical response number for the reply. GetResponse reads response lines from the connection, including continuation response messages until the terminal response message is received. All response messages are added to to the LastCmdResult property.

Use LastCmdResult to access the full text or numeric response number for the most recent response message, or multiple response messages.

GetResponse sets ResultNo to the three-digit numeric value from the most recent response message in LastCmdResult.

Finally, GetResponse calls CheckResponse using the values in ResultNo and AAllowedResponses to determine if the numeric response code is one of the numeric values allowed for the protocol action.


TIdTCPConnection.InputLn
TIdTCPConnection, See Also
Reads a line from the server connection, and echoes the data.
function InputLn(const AMask: String = ''; AEcho: Boolean = True; ATabWidth: Integer = 8; AMaxLineLength: Integer = -1): String;
Description
InputLn reads a line from the server and echoes it back honoring the backspace character. If AMask is specified, the AMask string is sent to the peer for each character received, instead of the actual characters which are read.

InputLn is useful when obtaining data from a user such as username, passwords, and commands.


TIdTCPConnection.OpenWriteBuffer
TIdTCPConnection, See Also
Indicates that the peer connection should use Indy internal buffering.
procedure OpenWriteBuffer(const AThreshhold: Integer = -1);
Parameters
const AThreshhold: Integer = -1
Number of bytes to buffer before flushing data in the write buffer to the peer. Default value is -1.
Description
OpenWriteBuffer is a procedure that is normally used to capture all data being sent to a peer, and to store the data in the Indy internal buffer until a call to CloseWriteBuffer or FlushWriteBuffer. Use OpenWriteBuffer when all data should be sent to the peer at one time.

AThreshold indicates the number of bytes that can accumulate in the Indy write buffer prior to using FlushWriteBuffer. The write buffer threshold is used to provide optimium data transfer without creating massive in memory buffers, or requiring the caller to periodically flush the buffer. When the write buffer size exceeds the threshold value, the connection will send a packet containing buffered data. The default value of AThreshold (-1) indicates that write buffering should be used for the entire write buffer. FlushWriteBuffer may also use a threshold value to determine the data packet size commited to the peer socket connection from the Indy internal buffer.

Use OpenWriteBuffer in a try...except block, like the following:

    OpenWriteBuffer;
    try;
    WriteStream(AStream);
    // Close the write buffer and have Indy now transmit it
    CloseWriteBuffer;
    except
    // Clear what we had buffered, and disable write buffering
    CancelWriteBuffer;
    // Re-raise the exception so it is not masked
    raise;
    end;

TIdTCPConnection.RaiseExceptionForLastCmdResult
TIdTCPConnection, See Also
Handles creating an exception when an error occurs during response processing.
procedure RaiseExceptionForLastCmdResult; virtual; overload;
Parameters
AException
Exception class tyope to use for creating this exception.
Description
RaiseExceptionForLastCmdResult is an overloaded procedure in TIdTCPConnection that allows the client or descendant classes to create an exception using another Indy exception class type and/or the values in LastCmdResult.

When the TClassIdException variant is used, an instance of the exception class is raised using the text specified in LastCmdResult. The default implementation raises an EIdProtocolReplyError exception using the numeric and text values in LastCmdResult.

RaiseExceptionForLastCmdResult is used when GetResponse validates the numeric codes and messages permitted in the protocol response message.


TIdTCPConnection.RaiseExceptionForLastCmdResult
TIdTCPConnection, See Also
Handles creating an exception when an error occurs during response processing.
procedure RaiseExceptionForLastCmdResult(AException: TClassIdException); virtual; overload;
Parameters
AException: TClassIdException
Exception class tyope to use for creating this exception.
Description
RaiseExceptionForLastCmdResult is an overloaded procedure in TIdTCPConnection that allows the client or descendant classes to create an exception using another Indy exception class type and/or the values in LastCmdResult.

When the TClassIdException variant is used, an instance of the exception class is raised using the text specified in LastCmdResult. The default implementation raises an EIdProtocolReplyError exception using the numeric and text values in LastCmdResult.

RaiseExceptionForLastCmdResult is used when GetResponse validates the numeric codes and messages permitted in the protocol response message.


TIdTCPConnection.ReadBuffer
TIdTCPConnection, See Also
Moves data from the Indy read buffer to a variable.
procedure ReadBuffer(var ABuffer; const AByteCount: Longint);
Parameters
var ABuffer
Destination for data from the Indy read buffer.
const AByteCount: Longint
Number of bytes to move to the ABuffer.
Description
ReadBuffer is a procedure used to get data from the internal Indy read buffer and store the result in the variable specified by ABuffer. AByteCount must be larger than 0, and ABuffer must contain a variable parameter, or ReadBuffer will not have any effect.

ReadBuffer calls ReadFromStack to insure that the Indy read buffer contains at least the number of bytes specified in AByteCount. ReadBuffer calls CheckForDisconnect to insure that the socket connection has not been closed. ReadBuffer removes the number of bytes specified from the internal TIdManagedBuffer.


TIdTCPConnection.ReadCardinal
TIdTCPConnection, See Also
Returns a cardinal read from the peer.
function ReadCardinal(const AConvert: boolean = true): Cardinal;
Parameters
const AConvert: boolean = true
Default is True. When true, the value is converted from Internet Byte order to the Native Intel Byte order. If false, no byte-order conversion is done.
Return Value
Cardinal - the 32 bit value which was received from the peer.
Description
This function reads a 32 bit unsigned (cardinal) value from the peer and returns it.

TIdTCPConnection.ReadChar
TIdTCPConnection, See Also
Returns a single character from the Indy read buffer.
function ReadChar: Char;
Description
ReadChar is a Char function that returns a single character value from the InputBuffer for the connection. ReadChar calls ReadBuffer to extract the ordinal value from InputBuffer.

ReadChar is used in InputLn to allow handling of values read from the connection on a character-by-character basis.


TIdTCPConnection.ReadFromStack
TIdTCPConnection, See Also
Reads data from the protocol stack using the socket binding.
function ReadFromStack(const ARaiseExceptionIfDisconnected: Boolean = True; ATimeout: Integer = IdTimeoutDefault; const ARaiseExceptionOnTimeout: Boolean = True): Integer; virtual;
Parameters
const ARaiseExceptionIfDisconnected: Boolean = True
Raise an Exception when disconnected. Default value is True.
ATimeout: Integer = IdTimeoutDefault
Timeout value to wait for a readble socket handle. Default value is IdTimeoutDefault.
const ARaiseExceptionOnTimeout: Boolean = True
Raise an exception when a timeout occurs. Default value is True.
Return Value
Integer - Number of bytes read from the protocol stack.
Description
ReadFromStack is an Integer function used to read data from the IP protocol stack for the peer connection into the Indy buffer maintained for the connection.

ATimeout indicates the number of milliseconds to wait for the IOHandler to become readable prior to reading data. When ATimeout contains the value IdTimeoutDefault, ReadTimeout will be used as the timeout value when it is non-zero. Otherwise, IdTimeoutInfinite is used as the timeout value. If a timeout occurs, an EIdReadTimeout exception will be raised when ARaiseExceptionOnTimeout is True. Otherwise ReadFromStack performs no additional processing, and uses -1 as the return value for the method.

ReadFromStack calls CheckForDisconnect using the value specifed in ARaiseExceptionIfDisconnected to determine if an exception is raised when the connection is closed. If the socket is not Connected, ReadFromStack will exit from the method.

ReadFromStack uses IOHandler to determine when the connection is readable, and to receive data from the input source. ReadFromStack updates ClosedGracefully indicating when all data has been read from the stack prior to closing the connection, and calls TIdStack.CheckForSocketError to determine if the connection closed abnormally.

When ClosedGracefully is False, the protocol stack is used to check for an Id_WSAESHUTDOWN error and allows the socket to disconnect when the error is detected. If the Indy read buffer contains no unread data, the Id_WSAESHUTDOWN exception is re-raised using the protocol stack handler.

ReadFromStack provides support for TIdConnectionIntercept by calling the Receive handler for the Intercept when Enabled. ReadFromStack also performs 8-bit to 7-bit character translations when ASCIIFilter is True.

Finally, ReadFromStack moves data read from the input source to the internal Indy buffer, and sets the return value to the number of bytes handled by the operation.

ReadFromStack can be a time intensive operation due to network contention and the nature of blocking sockets. ReadFromStack should be the only location where data is read from the protocol stack.


TIdTCPConnection.ReadInteger
TIdTCPConnection, See Also
Reads an integer value in the Indy buffer.
function ReadInteger(const AConvert: boolean = true): Integer;
Parameters
const AConvert: boolean = true
Indicates that the result should be converted from Internet to Intel byte-order. Default value is True.
Return Value
Integer - Value read from the Indy buffer.
Description
ReadInteger is an Integer function that reads a 4-byte binary integer value from the Indy buffer. By default, the resulting Integer value is converted from Internet byte-order to Intel byte-order. This can be overridden by setting AConvert to False.

ReadInteger uses ReadBuffer to read and extract the integer value from the Indy buffer. ReadInteger uses the WSNToHL method from TIdStackWinsock to convert the integer value from Internet byte-order to Intel byte-order.


TIdTCPConnection.ReadLn
TIdTCPConnection, See Also
Reads a line from the Indy buffer.
function ReadLn(ATerminator: string = LF; const ATimeout: Integer = IdTimeoutDefault; AMaxLineLength: Integer = -1): string; virtual;
Parameters
ATerminator: string = LF
End-of-line termination character or characters.
const ATimeout: Integer = IdTimeoutDefault
Time-out in milliseconds. Default value IdTimeoutInfinite.
Return Value
String - Line read from the buffer.
Description
ReadLn is a function that returns a string containing a single line from the buffer maintained by TIdTCPConnection.

The optional ATerminator parameter indicates the end-of-line symbol for the particular protocol. If data is expected, and you do not need a custom end-of-line symbol, you can use the default ATerminator value (#0). ATerminator values include:

  • #0 - Default Line Feed (#10)

  • LF - Line Feed (#10)

  • CR - Carriage Return (#13)

  • EOL - End-of-line (Carriage Return + Line Feed)

If there is no terminator (ATerminator) in the buffer, ReadLn will read more bytes from the TCP stack through the ReadFromStack method.

Use a custom time-out (ATimeout) value to change the number of milliseconds to wait for a response from the peer connection before a time-out occurs. The default value for ATimeout is IdTimeoutInfinite. See IdGlobal.pas for more information on constant timeout values.

ReadLn will return an empty string ('') if the peer connection is prematurely closed or a time-out occurs. When a timeout condition occurs in ReadLn, the ReadLnTimedOut property is set to True.


TIdTCPConnection.ReadLnWait
TIdTCPConnection
Returns a line of text from the connection.
function ReadLnWait(AFailCount: Integer = MaxInt): string;
Return Value
String - Data read from the connection.
Description
ReadLnWait is a procedure that returns a single line ot text from the connection. ReadLnWait will continue to read from the connection until a non-blank line is received.

If there is no guarantee that data will be available, or a specific line delimiter is required, use ReadLn to retrieve data from the connection.

ReadLnWait calls ReadLn with the default delimiter and timeout values.


TIdTCPConnection.ReadSmallInt
TIdTCPConnection
Reads an small integer value from the connection.
function ReadSmallInt(const AConvert: boolean = true): SmallInt;
Parameters
const AConvert: boolean = true
Convert the numeric from Network to Host representation. Default value is True.
Return Value
SmallInt - Value read from the Indy buffer.
Description
ReadSmallInt is a SmallInt function used to read an integer value, in the range 0 to 255, from the connection. ReadSmallInt uses ReadBuffer to get the SmallInt value from the Indy read buffer.

AConvert indicates that the protocol stack WSNToHs method should be used to convert the numeric value from Network byte-order to Host-specific byte-order.


TIdTCPConnection.ReadStream
TIdTCPConnection, See Also, Example
Reads data from the Indy buffer and stores the values in a stream.
procedure ReadStream(AStream: TStream; AByteCount: LongInt = -1; const AReadUntilDisconnect: boolean = false);
Parameters
AStream: TStream
Stream where data will be stored.
AByteCount: LongInt = -1
Number of bytes to be read. Default value is -1.
const AReadUntilDisconnect: boolean = false
Indicates that data should be read from the protocol stack until disconnected. Default value is False.
Description
ReadStream is a procedure used to read and extract data from the Indy buffer, and to place the resulting values in the stream specified in AStream.

AByteCount indicates the number of bytes to be read from the Indy buffer, or -1 if all bytes in the Indy buffer should be included. When AByteCount contains the number of bytes to be read, it is used to increase the size of AStream by the given number of bytes. This reduces memory or disk allocations to a single operation.

AReadUntilDisconnected indicates that data should be read from the protocol stack until the component is disconnected. When AReadUntilDisconnected is True, bytes are read from the protocol stack and written to AStream until Connected is False.

Note: When AByteCount is -1, and AReadUntilDisconnected is False, it is assumed that the first 4-bytes in the Indy buffer contains the length of buffered data in Internet format. ReadStream uses ReadInteger to convert the value to Intel byte-order prior to reading the remaining data from the Indy buffer.


TIdTCPConnection.ReadString
TIdTCPConnection, See Also
Reads a string value from the connection.
function ReadString(const ABytes: Integer): string;
Parameters
const ABytes: Integer
Number of bytes to be read from the connection.
Return Value
String - Data read from the Indy read buffer.
Description
ReadString is a String function used to read the number of bytes specified in ABytes from the connection. ReadString uses ReadBuffer to get the string from the Indy read buffer.

ReadString delays until the number of bytes in ABytes is available in the Indy read buffer. If the number of bytes is not known, use ReadLn or ReadLnWait.


TIdTCPConnection.ReadStrings
TIdTCPConnection, See Also
Reads a variable number of text lines from a connection.
procedure ReadStrings(var AValue: TStrings; AReadLinesCount: Integer = -1);
Parameters
var AValue: TStrings
Container for values read from the connection.
AReadLinesCount: Integer = -1
Number of lines to read from the connection.
Description
ReadStrings is a procedure that allows the TCP connection to read a variable number of text lines, and store the values in the variable parameter AValue.

AReadLinesCount is the number of lines expected from the TCP connection, or -1 when the connection will contain an Integer that indicates the number of lines to be read. ReadStrings calls ReadInteger to get the line count when AReadLinesCount contains -1.

ReadStrings repetitively calls ReadLn until the number of expected lines has been read from the TCP connection.


TIdTCPConnection.SendCmd
TIdTCPConnection, See Also
Sends a command to the peer.
function SendCmd(const AOut: string; const AResponse: SmallInt = -1): SmallInt; overload;
function SendCmd(const AOut: string; const AResponse: Array of SmallInt): SmallInt; virtual; overload;
Parameters
const AOut: string
Command to be sent to the server.
const AResponse: SmallInt = -1
Numeric response expected. Default is -1. (Array of SmallInt for multiple responses allowed).
Description
SendCmd sends the command specified in AOut to the peer. If the numeric response code is not AResponse, an exception is raised. If you have to check for more than one numeric response number code, pass an array of numbers in AResponse. If you do not want an exception raised, omit AResponse.

Use LastCmdResult to access the numeric and text portions of the response for the command.


TIdTCPConnection.SendCmd
TIdTCPConnection, See Also
Sends a command to the peer.
function SendCmd(const AOut: string; const AResponse: SmallInt = -1): SmallInt; overload;
function SendCmd(const AOut: string; const AResponse: Array of SmallInt): SmallInt; virtual; overload;
Parameters
const AOut: string
Command to be sent to the server.
const AResponse: SmallInt = -1
Numeric response expected. Default is -1. (Array of SmallInt for multiple responses allowed).
Description
SendCmd sends the command specified in AOut to the peer. If the numeric response code is not AResponse, an exception is raised. If you have to check for more than one numeric response number code, pass an array of numbers in AResponse. If you do not want an exception raised, omit AResponse.

Use LastCmdResult to access the numeric and text portions of the response for the command.


TIdTCPConnection.WaitFor
TIdTCPConnection, See Also
Reads data from the peer connection until a string is found.
function WaitFor(const AString: string): string;
Parameters
const AString: string
The value to be located.
Return Value
String - Value read from the connection.
Description
WaitFor is a String function used to read from the connection until the value in AString is encountered. The return value for WaitFor will include the value in AString.

WaitFor calls CheckForDisconnect to detect when the connection is closed.


TIdTCPConnection.Write
TIdTCPConnection, See Also
Send a string using the connection.
procedure Write(const AOut: string); virtual;
Parameters
const AOut: string
Buffer to send over the connection.
Description
Write is a procedure used to send the string specified in AOut over the connection. When AOut is an empty string, no action is performed.

Write calls WriteBuffer to perform output from the buffer.

Write does not add an End-Of-Line sequence to the output buffer.


TIdTCPConnection.WriteBuffer
TIdTCPConnection, See Also
Sends the data in a buffer to a peer connection.
procedure WriteBuffer(const ABuffer; AByteCount: Longint; const AWriteNow: Boolean = False);
Parameters
const ABuffer
Buffer with data to be written.
AByteCount: Longint
Number of bytes of data to be written.
const AWriteNow: Boolean = False
Ignore write buffering and send data immediately. Default value is False.
Description
WriteBuffer is a procedure that places data in the Indy buffer for the peer connection, or optionally sends the data to the peer connection. Note: This is the only place where data is sent to a peer through the socket binding allocated for a connection. All other write procedures call this method.

ABuffer is the TIdBuffer that contains data to be affected by WriteBuffer.

AByteCount is the number of bytes in the buffer to be affected by WriteBuffer.

When AWriteNow is True, write buffering will be ignored and ABuffer will be transmitted to the peer without updating the internal Indy write buffer. Note: If this is done after a call to OpenWriteBuffer, ABuffer will be transmitted before/in the middle of any data in the Indy internal write buffer.

Call OpenWriteBuffer to initiate use of Indy internal write buffering operations.

Call CancelWriteBuffer or CloseWriteBuffer to interrupt use of the internal Indy write buffer.

Call FlushWriteBuffer to force unsent data in the Indy internal write buffer to be sent to the peer connection.

Call ClearWriteBuffer to remove any unsent data in the Indy internal write buffer.


TIdTCPConnection.WriteCardinal
TIdTCPConnection, See Also
Sends a cardinal to the peer.
procedure WriteCardinal(AValue: Cardinal; const AConvert: Boolean = True);
Parameters
AValue: Cardinal
The 32bit value to send to the peer.
const AConvert: Boolean = True
Default is True. When true, the value is converted to Internet Byte order from the Native Intel Byte order. If false, no byte-order conversion is done.
Description
This procedure sends a 32-bit unsigned value (cardinal) to the peer. The TIdTimeServer component uses WriteCardinal to send a time value to the peer connection.

Use ReadCardinal to read a 32-bit unsigned value from the peer connection.


TIdTCPConnection.WriteFile
TIdTCPConnection, See Also
Sends an operating system file to the peer on the connection.
function WriteFile(const AFile: String; const AEnableTransferFile: Boolean = False): Cardinal; virtual;
Parameters
const AFile: String
File to send.
const AEnableTransferFile: Boolean = False
Use OS-specific extenstions to send the file. Default value is False.
Return Value
Cardinal - Number of bytes written to the peer.
Description
WriteFile is a Cardinal function used to send the operating system file specified in AFile to the peer on the connection. WriteFile is used to transfer files in server implementations like HTTP and FTP.

When AEnableTransferFile is True, Windows NT and Windows 2000 server can increase the efficiency of tile transfer operations, but cannot support TIdIntercept or progress indicators. AEnableTransferFile has no effect on Windows 95 and Windows 98.

Otherwise, WriteFile calls WriteStream using a TFileStream for the file specified in AFile to perform write operations over the connection.

WriteFile can raise a EIdFileNotFound exception when AFile does not exist on the local file system.


TIdTCPConnection.WriteHeader
TIdTCPConnection, See Also
Sends a protocol header from values in a list.
procedure WriteHeader(AHeader: TStrings);
Parameters
axHeader
List of headers to write to the connection.
Description
WriteHeader is a procedure used to write the header items in axHeader to the connection. axHeader contains header items in NAME=VALUE form. WriteHeader will translate each line in axHeader to the HTTP header form NAME: VALUE.

WriteHeader calls WriteLn for each header item in axHeader. An additional blank line is written to the connection at the end of the header list.


TIdTCPConnection.WriteInteger
TIdTCPConnection, See Also
Writes a binary integer value to the peer connection.
procedure WriteInteger(AValue: Integer; const AConvert: Boolean = True);
Parameters
AValue: Integer
The integer value to send to the peer.
const AConvert: Boolean = True
Convert the Host byte-order to Network byte-order. Default value is True.
Description
WriteInteger is a procedure used to send an Integer value to the peer connection.

AValue is the integer value to send to the peer connection.

AConvert indicates that the integer in AValue should be converted from local host byte-order to Internet byte-order. When AConvertis True, the protcol stack method WSHToNl is called to convert the binary integer value.

WriteInteger calls WriteBuffer to send AValue to the peer connection.


TIdTCPConnection.WriteLn
TIdTCPConnection, See Also
Writes string value to the peer connection.
procedure WriteLn(const AOut: string = ''); virtual;
Parameters
const AOut: string = ''
Value to send to the peer connection. Default value is ''.
Description
WriteLn is a procedure used to send the string value specified in AOut to the peer connection. WriteLn appends the EOL character sequence to the value in AOut when it is sent to the peer connection.

TIdTCPConnection.WriteRFCReply
TIdTCPConnection, See Also
Sends an RFC response message on the connection.
procedure WriteRFCReply(AReply: TIdRFCReply);
Parameters
AReply: TIdRFCReply
RFC response message to be sent on the connection.
Description
WriteRFCReply is a procedure used to send the value of the TIdRFCReply specified in AReply on the current connection. WriteRFCReply calls the Write method using the value supplied by TIdRFCReply.GenerateReply when the RFC response message contains non-blank values.

TIdTCPConnection.WriteRFCStrings
TIdTCPConnection, See Also
Write RFC-compliant response messages on the connection.
procedure WriteRFCStrings(AStrings: TStrings);
Parameters
AStrings: TStrings
TStringLIst to be written on the connection.
Description
WriteRFCStrings is a procedure used to write the TStrings values in AStrings on the connection in a format consistent with RFC message responses. WriteRFCStrings insures that individual lines in AStrings beginning with the response termination character '.' are converted to '..', and call WriteLn using the updated values. When all lines have been written, WriteRFCStrings calls WriteLn to send the '.' termination character to indicate the end of RFC response messages.

TIdTCPConnection.WriteSmallInt
TIdTCPConnection, See Also
Sends a small integer value to the peer connection.
procedure WriteSmallInt(AValue: SmallInt; const AConvert: Boolean = True);
Parameters
AValue: SmallInt
Value to be sent to the peer.
const AConvert: Boolean = True
Convert the value from local host byte-order to Internet byte-order. Default value is True.
Description
WriteSmallInt is a procedure used to send the SmallInt specified in AValue to the peer connection.

When AConvert is True, the value specified in AValue is converted to Internet byte-order using the prtocol stack method WSHToNs.

WriteSmallInt calls WriteBuffer to send the SmallInt value to the peer connection.


TIdTCPConnection.WriteStream
TIdTCPConnection, See Also
Sends a stream of data to the peer connection.
procedure WriteStream(AStream: TStream; const AAll: Boolean = True; const AWriteByteCount: Boolean = False; const ASize: Integer = 0); virtual;
Parameters
AStream: TStream
The stream to send to the peer connection.
const AAll: Boolean = True
Write from the start of the stream. Default value is True.
const AWriteByteCount: Boolean = False
Write the stream sizew to the peer connection. Default value is False.
Description
WriteStream is a procedure used to send the contents of the TStream descendant specified in AStream to the peer connection.

AAll indicates that the stream should be positioned to the stream origin prior to sending stream data.

AWriteByteCount indicates that the Integer value containing the size of the stream should be written to the peer connection prior to the stream data. When AAll is true, this value reflects the size of the entire stream. When AAll is False, this value indicates the stream sixe from the current stream position to the end of the stream. When AWriteByteCount is True, WriteInteger is called to send the stream size to the peer connection.

WriteStream calls BeginWork with the work mode wmWrite and the size of the stream prior to sending stream data to the peer connection. The stream size is the value in AStream.Size, and is stored in a variable for subsequent use in the method. This reduces the overhead for TStream descendants where TStream.Seek is not efficient or practical.

AStream data is sent to the peer in blocks, where each block is read into a buffer that can contain up to SendBufferSize bytes. If a read from AStream results in a buffer with a length of 0, when the stream size and position indicate a non-zero value, an EIdNoDataToRead exception will be raised. Data read from AStream is sent on the connection using WriteBuffer with the current buffer contents and size.

WriteStream calls EndWork with the work mode wmWrite prior to exiting from the method.


TIdTCPConnection.WriteStrings
TIdTCPConnection, See Also
Write multiple text strings to a peer connection.
procedure WriteStrings(AValue: TStrings; const AWriteLinesCount: Boolean = False);
Parameters
AValue: TStrings
Values to be sent as output to the peer.
Description
WriteStrings is a procedure used to send the multiple lines of text in AValue to the socket peer connection. WriteStrings uses the WriteLn method to send individual lines in AValue.

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