Indy 9
TIdSimpleServer
Hierarchy, Properties, Methods, Events, See Also, Unit: IdSimpleServer
Implements a single-threaded TCP Server.
TIdSimpleServer = class(TIdTCPConnection)
Unit
IdSimpleServer
Description
TIdSimpleServer is a TIdTCPConnection descendant that implements a single-threaded TCP (Transmission Control Protocol) server. TIdSimpleServer is essentially a TCP connection that gains the ability to listen for serial connection requests.

TIdSimpleServer can be used as a base class to create custom single-threaded TCP server descendants.


TIdSimpleServer.AcceptWait
TIdSimpleServer, See Also
Timeout for accepting a new connection.
property AcceptWait: integer;
Description
AcceptWait is an Integer property that defines the timeout for accepting a new connection on the TIdSocketHandle in Binding. AcceptWait is expressed in milliseconds.

AcceptWait is used in Listen to determine if the TIdSocketHandle allocated to Binding is readable.


TIdSimpleServer.Binding
TIdSimpleServer, See Also
Socket descriptor used to listen for connection requests.
property Binding: TIdSocketHandle;
Description
Binding is a TIdSocketHandle property that represents the socket descriptor used by TIdSimpleServer to Listen for serial connection requests.

Binding is allocated in the CreateBinding method.

Binding is used when TIdSimpleServer begins to listen for connection requests. If Binding is not assigned, ResetConnection is called and the Binding is initialized using CreateBinding.

Binding is also used when the socket handle for the specified BoundIP and BoundPort is bound in the Bind method.


TIdSimpleServer.BoundIP
TIdSimpleServer, See Also
IP address used by the server.
property BoundIP: string;
Description
BoundIP is a String property used to identify the IP address of the server. BoundIP and BoundPort are used when the socket handle for the server is allocated and bound in Listen.

BoundIP exists because Binding is not a published property (it is public) and cannot be streamed without the TIdSocketHandles collection that owns the Binding.


TIdSimpleServer.BoundPort
TIdSimpleServer, See Also
Port number used by the server.
property BoundPort: Integer;
Description
BoundPort is an Integer property used to identify the port number for the server. BoundIP and BoundPort are used when the socket handle for the server is allocated and bound in Listen.

BoundPort exists because Binding is not a published property, it is public, and cannot be streamed without the TIdSocketHandles collection that owns the Binding.


TIdSimpleServer.ListenHandle
TIdSimpleServer, See Also
Represents the socket handle for the listener thread.
property ListenHandle: TIdStackSocketHandle;
Description
ListenHandle is a read-only TIdStackSocketHandle property that represents the socket handle allocated for the server lister thread. ListenHandle contains Id_INVALID_SOCKET when no socket handle has been allocated for the listener thread.

ListenHandle is updated in Create, Bind, and Listen.


TIdSimpleServer.Abort
TIdSimpleServer, See Also
Instructs a server to stop listening.
procedure Abort; virtual;
Description
Abort is a procedure that instructs TIdSimpleServer to stop listening for connection requests. After calling Abort, the server will close the listening socket handle and force an exit from the Listen method.

TIdSimpleServer.BeginListen
TIdSimpleServer, See Also
Initializes the listener thread for the server.
procedure BeginListen; virtual;
Description
BeginListen is a procedure used initialize the connection state and insure that the ListenHandle has called Bind.

BeginListen calls ResetConnection to clear the internal flags used by the server. BeginListen calls the Listen method for Binding and sets the internal flag that indicates that the server is listening for client connections.

BeginListen is called from Listen prior to entering the control loop for the listener.


TIdSimpleServer.Bind
TIdSimpleServer, See Also
Allocates and binds the socket handle for the listener thread.
procedure Bind; virtual;
Description
Bind is a procedure used to allocate the socket handle for the listener thread, and bind the address specified in BoundIP and BoundPort.

ListenHandle will contain the handle for the Binding. If an exception occurs, ListenHandle is assigned the value Id_INVALID_SOCKET and the exception is raised.


TIdSimpleServer.Create
TIdSimpleServer, See Also
Constructor for the object instance.
constructor Create(AOwner: TComponent); override;
Description
Create is the constructor for the object instance, and relies on the inherited Create method. Create sets the value of ListenHandle to Id_INVALID_SOCKET prior to exiting from the method.

TIdSimpleServer.CreateBinding
TIdSimpleServer, See Also
Sets the socket descriptor used in the IO Handler.
procedure CreateBinding;
Description
CreateBinding is a procedure used to initialize the IOHandler for the server to a TIdIOHandlerSocket instance, and assigns the binding in the IOHandler to the Binding property. CreateBinding also Opens the IOHandler.

CreateBinding is called from the BeginListen method, to prepare the server to accept connection requests.


TIdSimpleServer.EndListen
TIdSimpleServer, See Also
Stops the servers from accepting connection requests.
procedure EndListen; virtual;
Description
EndListen is a procedure used to inform the server that it can no longer accept connection requests. EndListen calls ResetConnection to clear the Indy buffer and internal state flags.

TIdSimpleServer.Listen
TIdSimpleServer, See Also
Allows a server to listen for a client connection.
function Listen: Boolean; virtual;
Return Value
Boolean - True on success, False on error.
Description
Listen is a Boolean function that allows TIdSimpleServer to listen for serial connection requests. Listen returns True when a connection request is detected, accepted, and is readable. Listen returns False if the AcceptWait timeout period elapses while trying to select the socket handle, or the Abort procedure is called.

Listen call BeginListen to initialize the server socket handle and state prior to entering the listener thread of execution. Listen provides a control loop that uses both AbortRequested and the socket handle Binding to determine when the server should stop listening for a client connection.

While AbortRequested is False, Listen will insure that the Binding is readable using the AcceptWait timeout value. When a connection request is detected, Listen calls Accept using the Handle for Binding.

When AbortRequested is True or a new connection has handled with Accept, Listen will close and invalidate the socket handle in ListenHandle.


TIdSimpleServer.ResetConnection
TIdSimpleServer, See Also
Clears connection and state indicators for the server.
procedure ResetConnection; override;
Description
ResetConnection is a procedure used to clear the values in AbortedRequested and Listening prior to entering the control loop for the listener thread. ResetConnection calls the inherited ResetConnection method.

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