Indy 9
|
TIdUDPListenerThread = class(TIdThread)
property AcceptWait: integer;
AcceptWait is used in the Run method to determine if the TIdSocketHandle in Server.Bindings is readable.
constructor Create(const ABufferSize: integer; Owner: TIdUDPServer); reintroduce;
ABufferSize is normally set to the value in TIdUDPServer.BufferSize when the listener thread is created.
Create also initializes the following:
destructor Destroy; override;
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.
procedure Run; override;
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.
procedure UDPRead;
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.