TIPAsyncSocket

Overview

The TIPAsyncSocket class is an implementation of the TIPBaseAsyncSocket class based on Synapse. It uses the TIPSocketWorkerThread class to provide a nonblocking use of sockets.

Location


 

constructor Create    (declared in TIPBaseAsyncSocket)

Creates a new instance.

constructor Create

constructor Create (TIPSocketMode)  overload

Uses the aHandle socket with the aMode address family specification in nonblocking mode.

constructor Create(aMode: TIPSocketMode)

Parameters:

  • aMode: Address family specification

constructor Create (TIPSocketMode, TSocket)  overload

Uses the aHandle socket with the aMode address family specification and sets aHandle in nonblocking mode.

constructor Create(aMode: TIPSocketMode; aHandle: TSocket)

Parameters:

  • aMode: Address family specification
  • aHandle: Existing socket

BeginAccept  override

Initiates the acceptance of client requests on this socket and calls aCallback when an accept occurs.

procedure BeginAccept(aCallback: TIPSocketCallback)

Parameters:

  • aCallback: Callback method

BeginConnect  override

Initiates a connect operation to the given aIp and aPort endpoint on this socket and call aCallback when a connect occurs.

procedure BeginConnect(const aIp: string; aPort: Integer; aCallback: TIPSocketCallback)

Parameters:

  • aIp: IP address of the peer to which the socket is to be connected.
  • aPort: Numeric value of required service.
  • aCallback: Callback to be notified of the event.

BeginDisconnect  override

Initiates a disconnect on this socket and call aCallback when a disconnect occurs.

procedure BeginDisconnect(aCallback: TIPSocketCallback)

Parameters:

  • aCallback: Callback method that will receive and correctly process the result of disconnect.

BeginReadLine    (declared in TIPBaseAsyncSocket)

Initiates the reading of a sequence of chars until (optional CR (#13)) LF (#10) and registers aCallback to call when the line is ready. BeginReadLine is allowed for buffered sockets (Buffered=True) only.
If a received line already exists, aCallback is called immediately in the context of the current thread. Otherwise, the instrumental IntBeginReceive method is called with the ReadLineCallback as argument.

procedure BeginReadLine(aCallback: TIPSocketCallback)

Parameters:

  • aCallback:

BeginReceive    (declared in TIPBaseAsyncSocket)

Initiates the receiving of the aLength data block to store in aData by the aStart offset and registers aCallback to call when the whole block (for buffered sockets) or part of the block is ready. If the socket is not buffered (Buffered=False), the job is delegated to the instrumental IntBeginReceive method. Otherwise, the job is delegated to the TIPBaseAsyncSocket.BufferedBeginReceive with the TIPBaseAsyncSocket.BufferedReceiveCallback as argument.

procedure BeginReceive(aData: Pointer; aStart: Integer; aLength: Integer; aCallback: TIPSocketCallback)

Parameters:

  • aData: Destination base address
  • aStart: Offset from aData to store received data.
  • aLength: Size of the block to be received.
  • aCallback:

BeginSend    (declared in TIPBaseAsyncSocket)

Initiates the sending of the aLength data block from aData by the aStart offset and registers aCallback to call when the whole block (for buffered sockets) or part of the block is sent. If the socket is not buffered (Buffered=False), the job is delegated to the instrumental IntBeginSend method with aCallback, otherwise with TIPBaseAsyncSocket.BufferedSendCallback as argument.

procedure BeginSend(aData: Pointer; aStart: Integer; aLength: Integer; aCallback: TIPSocketCallback)

Parameters:

  • aData: Base address for sending data
  • aStart: Offset from aData
  • aLength: Size of the block to be sent
  • aCallback:

Bind  override

Implements TIPBaseAsyncSocket to perform a binding according to the TIPSocketMode specified on creation.

procedure Bind(const aIp: string; aPort: Integer)

Parameters:

  • aIp: IP address to assign to this socket
  • aPort: Numeric value of the offered service

Buffered    (declared in TIPBaseAsyncSocket)

Controls if background data collecting is enabled. The *ReadLine methods are disabled when Buffered is false.

property Buffered: Boolean read write

BufferReadLine    (declared in TIPBaseAsyncSocket)

If the buffer contains data with a terminating LF (#10), it is copied into aLine and true is returned. Otherwise, false is returned. This method raises an EIPSocketError, if Buffered=False.

function BufferReadLine(var aLine: AnsiString): Boolean

Parameters:

  • aLine: Resulting string

EndAccept  override

Implements TIPBaseAsyncSocket by calling synsock.Accept and constructing a new TIPAsyncSocket based on the socket handle returned by synsock.Accept. The callback registered by BeginAccept is cleared and the created TIPAsyncSocket instance is returned.

function EndAccept: TIPBaseAsyncSocket

EndConnect  override

Ends the connection to the remote socket with the specified address.

function EndConnect: Boolean

EndDisconnect  override

Clean up a broken connection.

procedure EndDisconnect

EndReadLine    (declared in TIPBaseAsyncSocket)

Copies the string collected by the ReadLineCallback into aLine and returns true, if any unread data remains. Note that the return value applies to further read operations.

function EndReadLine(var aLine: string): Boolean

Parameters:

  • aLine: Resulting string

EndReceive    (declared in TIPBaseAsyncSocket)

If the socket is not buffered (Buffered=False), this method returns the result of calling the instrumental IntEndReceive method. Otherwise, it returns the amount of data collected by the BufferedEndReceive.

function EndReceive: Integer

EndSend    (declared in TIPBaseAsyncSocket)

If the socket is not buffered (Buffered=False), this method returns the result of calling the instrumental IntEndSend method. Otherwise, it returns the amount of data recorded by the BufferedSendCallback and clears the callback registered by BeginSend.

function EndSend: Integer

GetLocalIp  override

Retrieves the local endpoint of the transport layer.

function GetLocalIp: string

GetLocalPort  override

Retrieves the numeric value associated with the offered service by the transport layer.

function GetLocalPort: Integer

GetRemoteIp  override

Retrieves the IP of the peer.

function GetRemoteIp: string

GetRemotePort  override

Gets the port of the peer used for communication.

function GetRemotePort: Integer

IdleTimeout    (declared in TIPBaseAsyncSocket)

Determines the admissible interval in seconds between send or receive operations.

property IdleTimeout: Integer read write

Listen  override

Establishes a socket to listen for an incoming connection.

procedure Listen(aBacklog: Integer)

Parameters:

  • aBacklog: Desired maximum length of the queue of pending connections. This value may be changed by the transport layer.

MaxLineLength    (declared in TIPBaseAsyncSocket)

property MaxLineLength: Integer read write

NoDelay    (declared in TIPBaseAsyncSocket)

Controls TCP packet batching (Nagle's algorithm).
TCP normally batches small logical packets into single larger physical packets (by briefly delaying packets) to fill physical network frames with as much data as possible. This is intended to improve network throughput in terminal emulation environments where mostly keystrokes are being sent across the network. Setting NoDelay to true disables TCP packet batching. Disabling TCP packet batching means that packets are sent regardless of size; this increases the volume of network traffic.

property NoDelay: Boolean read write

OnDisconnected    (declared in TIPBaseAsyncSocket)

Allows access to the callback that is called when the transport layer detects a connection break.

property OnDisconnected: TIPSocketCallback read write
delegate: procedure OnDisconnected(Sender: TIPBaseAsyncSocket)

OnTimeout    (declared in TIPBaseAsyncSocket)

Allows access to a callback which is called when IdleTimeout is not 0 and interval inactivity is greater than IdleTimeout. Note that with the TIPAsyncSocket class, an OnTimeout will be called in a TIPSocketWorkerThread context.

property OnTimeout: TIPSocketCallback read write
delegate: procedure OnTimeout(Sender: TIPBaseAsyncSocket)

ReceiverBufferSize    (declared in TIPBaseAsyncSocket)

Controls the size of the receiving data buffer of the transport layer. Note that the transport layer may not provide the requested size, so you have to read ReceiverBufferSize to check the buffer size actually provided.

property ReceiverBufferSize: Integer read write

SendBufferSize    (declared in TIPBaseAsyncSocket)

Controls the size of the sending data buffer of the transport layer. Note that the transport layer may not provide the requested size, so you have to read SendBufferSize to check the buffer size actually provided.

property SendBufferSize: Integer read write

 

Buffered    (declared in TIPBaseAsyncSocket)

Controls if background data collecting is enabled. The *ReadLine methods are disabled when Buffered is false.

property Buffered: Boolean read write

IdleTimeout    (declared in TIPBaseAsyncSocket)

Determines the admissible interval in seconds between send or receive operations.

property IdleTimeout: Integer read write

MaxLineLength    (declared in TIPBaseAsyncSocket)

property MaxLineLength: Integer read write

NoDelay    (declared in TIPBaseAsyncSocket)

Controls TCP packet batching (Nagle's algorithm).
TCP normally batches small logical packets into single larger physical packets (by briefly delaying packets) to fill physical network frames with as much data as possible. This is intended to improve network throughput in terminal emulation environments where mostly keystrokes are being sent across the network. Setting NoDelay to true disables TCP packet batching. Disabling TCP packet batching means that packets are sent regardless of size; this increases the volume of network traffic.

property NoDelay: Boolean read write

ReceiverBufferSize    (declared in TIPBaseAsyncSocket)

Controls the size of the receiving data buffer of the transport layer. Note that the transport layer may not provide the requested size, so you have to read ReceiverBufferSize to check the buffer size actually provided.

property ReceiverBufferSize: Integer read write

SendBufferSize    (declared in TIPBaseAsyncSocket)

Controls the size of the sending data buffer of the transport layer. Note that the transport layer may not provide the requested size, so you have to read SendBufferSize to check the buffer size actually provided.

property SendBufferSize: Integer read write

 

constructor Create    (declared in TIPBaseAsyncSocket)

Creates a new instance.

constructor Create

constructor Create (TIPSocketMode)  overload

Uses the aHandle socket with the aMode address family specification in nonblocking mode.

constructor Create(aMode: TIPSocketMode)

Parameters:

  • aMode: Address family specification

constructor Create (TIPSocketMode, TSocket)  overload

Uses the aHandle socket with the aMode address family specification and sets aHandle in nonblocking mode.

constructor Create(aMode: TIPSocketMode; aHandle: TSocket)

Parameters:

  • aMode: Address family specification
  • aHandle: Existing socket

BeginAccept  override

Initiates the acceptance of client requests on this socket and calls aCallback when an accept occurs.

procedure BeginAccept(aCallback: TIPSocketCallback)

Parameters:

  • aCallback: Callback method

BeginConnect  override

Initiates a connect operation to the given aIp and aPort endpoint on this socket and call aCallback when a connect occurs.

procedure BeginConnect(const aIp: string; aPort: Integer; aCallback: TIPSocketCallback)

Parameters:

  • aIp: IP address of the peer to which the socket is to be connected.
  • aPort: Numeric value of required service.
  • aCallback: Callback to be notified of the event.

BeginDisconnect  override

Initiates a disconnect on this socket and call aCallback when a disconnect occurs.

procedure BeginDisconnect(aCallback: TIPSocketCallback)

Parameters:

  • aCallback: Callback method that will receive and correctly process the result of disconnect.

BeginReadLine    (declared in TIPBaseAsyncSocket)

Initiates the reading of a sequence of chars until (optional CR (#13)) LF (#10) and registers aCallback to call when the line is ready. BeginReadLine is allowed for buffered sockets (Buffered=True) only.
If a received line already exists, aCallback is called immediately in the context of the current thread. Otherwise, the instrumental IntBeginReceive method is called with the ReadLineCallback as argument.

procedure BeginReadLine(aCallback: TIPSocketCallback)

Parameters:

  • aCallback:

BeginReceive    (declared in TIPBaseAsyncSocket)

Initiates the receiving of the aLength data block to store in aData by the aStart offset and registers aCallback to call when the whole block (for buffered sockets) or part of the block is ready. If the socket is not buffered (Buffered=False), the job is delegated to the instrumental IntBeginReceive method. Otherwise, the job is delegated to the TIPBaseAsyncSocket.BufferedBeginReceive with the TIPBaseAsyncSocket.BufferedReceiveCallback as argument.

procedure BeginReceive(aData: Pointer; aStart: Integer; aLength: Integer; aCallback: TIPSocketCallback)

Parameters:

  • aData: Destination base address
  • aStart: Offset from aData to store received data.
  • aLength: Size of the block to be received.
  • aCallback:

BeginSend    (declared in TIPBaseAsyncSocket)

Initiates the sending of the aLength data block from aData by the aStart offset and registers aCallback to call when the whole block (for buffered sockets) or part of the block is sent. If the socket is not buffered (Buffered=False), the job is delegated to the instrumental IntBeginSend method with aCallback, otherwise with TIPBaseAsyncSocket.BufferedSendCallback as argument.

procedure BeginSend(aData: Pointer; aStart: Integer; aLength: Integer; aCallback: TIPSocketCallback)

Parameters:

  • aData: Base address for sending data
  • aStart: Offset from aData
  • aLength: Size of the block to be sent
  • aCallback:

Bind  override

Implements TIPBaseAsyncSocket to perform a binding according to the TIPSocketMode specified on creation.

procedure Bind(const aIp: string; aPort: Integer)

Parameters:

  • aIp: IP address to assign to this socket
  • aPort: Numeric value of the offered service

BufferReadLine    (declared in TIPBaseAsyncSocket)

If the buffer contains data with a terminating LF (#10), it is copied into aLine and true is returned. Otherwise, false is returned. This method raises an EIPSocketError, if Buffered=False.

function BufferReadLine(var aLine: AnsiString): Boolean

Parameters:

  • aLine: Resulting string

EndAccept  override

Implements TIPBaseAsyncSocket by calling synsock.Accept and constructing a new TIPAsyncSocket based on the socket handle returned by synsock.Accept. The callback registered by BeginAccept is cleared and the created TIPAsyncSocket instance is returned.

function EndAccept: TIPBaseAsyncSocket

EndConnect  override

Ends the connection to the remote socket with the specified address.

function EndConnect: Boolean

EndDisconnect  override

Clean up a broken connection.

procedure EndDisconnect

EndReadLine    (declared in TIPBaseAsyncSocket)

Copies the string collected by the ReadLineCallback into aLine and returns true, if any unread data remains. Note that the return value applies to further read operations.

function EndReadLine(var aLine: string): Boolean

Parameters:

  • aLine: Resulting string

EndReceive    (declared in TIPBaseAsyncSocket)

If the socket is not buffered (Buffered=False), this method returns the result of calling the instrumental IntEndReceive method. Otherwise, it returns the amount of data collected by the BufferedEndReceive.

function EndReceive: Integer

EndSend    (declared in TIPBaseAsyncSocket)

If the socket is not buffered (Buffered=False), this method returns the result of calling the instrumental IntEndSend method. Otherwise, it returns the amount of data recorded by the BufferedSendCallback and clears the callback registered by BeginSend.

function EndSend: Integer

GetLocalIp  override

Retrieves the local endpoint of the transport layer.

function GetLocalIp: string

GetLocalPort  override

Retrieves the numeric value associated with the offered service by the transport layer.

function GetLocalPort: Integer

GetRemoteIp  override

Retrieves the IP of the peer.

function GetRemoteIp: string

GetRemotePort  override

Gets the port of the peer used for communication.

function GetRemotePort: Integer

Listen  override

Establishes a socket to listen for an incoming connection.

procedure Listen(aBacklog: Integer)

Parameters:

  • aBacklog: Desired maximum length of the queue of pending connections. This value may be changed by the transport layer.

 

OnDisconnected    (declared in TIPBaseAsyncSocket)

Allows access to the callback that is called when the transport layer detects a connection break.

property OnDisconnected: TIPSocketCallback read write
delegate: procedure OnDisconnected(Sender: TIPBaseAsyncSocket)

OnTimeout    (declared in TIPBaseAsyncSocket)

Allows access to a callback which is called when IdleTimeout is not 0 and interval inactivity is greater than IdleTimeout. Note that with the TIPAsyncSocket class, an OnTimeout will be called in a TIPSocketWorkerThread context.

property OnTimeout: TIPSocketCallback read write
delegate: procedure OnTimeout(Sender: TIPBaseAsyncSocket)