Indy 9
TIdUDPListenerThread
Hierarchy, Properties, Methods, Events, See Also, Unit: IdUDPServer
Specifies the listener thread for TIdUDPServer.
TIdUDPListenerThread = class(TIdThread)
Unit
IdUDPServer
Description
TIdUDPListenerThread is a TIdThread descendant that is the listening thread for TIdUDPServer. TIdUDPListenerThread is used to detect arrival of data on socket bindings allocated by TIdUDPServer. When data is detected, the server is notified that data is available in Buffer using UDPRead.

TIdUDPListenerThread.AcceptWait
TIdUDPListenerThread, See Also
Time-out period for accepting new connections.
property AcceptWait: integer;
Description
AcceptWait is an Integer property that defines the time-out for accepting a new connection on the TIdSocketHandle in Server.Bindings. AcceptWait is expressed in milliseconds. The default value for AcceptWait is 1000 (1 second).

AcceptWait is used in the Run method to determine if the TIdSocketHandle in Server.Bindings is readable.


TIdUDPListenerThread.Create
TIdUDPListenerThread, See Also
Create is the constructor for the TIdUDPListenerThread object instance.
constructor Create(const ABufferSize: integer; Owner: TIdUDPServer); reintroduce;
Parameters
const ABufferSize: integer
Size of the buffer for the listener thread.
Owner: TIdUDPServer
Server that owns the listening thread.
Description
Create uses the inherited Create constructor to instantiate a suspended TIdUDPListenerThread. The listener thread Create constructor is called when the TIdUDPServer sets Active to True.

ABufferSize is normally set to the value in TIdUDPServer.BufferSize when the listener thread is created.

Create also initializes the following:

  • Sets AcceptWait to 1000 (ms) (1 second)

  • Creates the TMemoryStream Buffer

  • Sets Buffer.Size to ABufferSize

  • Sets Server to the owner of the listening thread.

TIdUDPListenerThread.Destroy
TIdUDPListenerThread
Destructor for the object instance.
destructor Destroy; override;
Description
Destroy is the destructor for TIdUDPListenerThread, and is responsible for disposing of the object instance. Destroy performs the following actions:

  • Free and release Buffer.

  • Calls the inherited Destroy method.

Destroy should not be directly called in an application. Use Free instead. Free checks to ensure that the object reference is not Nil before calling Destroy.

Note: If an exception is emitted from the constructor, the destructor is called to destroy the partially constructed object instance. Destructors should check that allocated resources, such as handles, were actually allocated before trying to release them.


TIdUDPListenerThread.Run
TIdUDPListenerThread, See Also
Performs the main thread of execution for the listener thread.
procedure Run; override;
Description
The Run method provides the main thread of execution for the TIdUDPListenerThread. Run insures that all TIdSocketHandles in Bindings are selected.

While the server is not Stopped, Run will check each socket handle for incoming data and receive the new data into Buffer. Buffer is repositioned to the beginning of the buffer after reading incoming data. Run will raise an EIdUDPReceiveErrorZeroBytes if there is an error reading from one of the socket handles.

Run uses the ThreadedEvent property of the TIdUDPServer to determine how read event notifications to the server are performed. When the server is using threaded events, Run calls UDPRead. Otherwise the UDPRead method is a synchronised method call.

Run is invoked by making the TIdUDPServer active when the listener thread is started.


TIdUDPListenerThread.UDPRead
TIdUDPListenerThread, See Also
Receives UDP data packets.
procedure UDPRead;
Description
UDPRead is a procedure that detects receipt of a UDP datagram in Buffer, and performs Server.DoUDPRead to make the data available.

UDPRead is a synchronised method in TIdUDPListenerThread, and uses the Server context to notify receipt of the data from the peer IP address and port number.


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