ThServerSocket   (HNetworks unit)

`ThServerSocket` is the server-side component for TCP/UDP listeners and thread-pool request handling.

ThServerSocket_Connection_Data

Runtime connection context passed into request-thread handlers.
Type
ThServerSocket_Connection_Data = record
  WinSocket: NativeUInt;
  Chilkat_Socket: HCkSocket;
  Accepted_From: ThServerSocket;
  UID: NativeUInt;
  Peer_IP: String;
end;

PhServerSocket_Connection_Data = ^ThServerSocket_Connection_Data;

Trt_ServerSocket_Connection_Helper.Occupied

Checks whether the connection record currently contains an active handle.
Function Trt_ServerSocket_Connection_Helper.Occupied: Boolean;

Trt_ServerSocket_Connection_Helper.Close_Socket

Closes WinSock/Chilkat handles tracked by the connection record.
Procedure Trt_ServerSocket_Connection_Helper.Close_Socket(CONST Linger: Boolean);

Trt_ServerSocket_Connection_Helper.Wait_For_Socket_Writability

Waits until the connection socket is writable.
Function Trt_ServerSocket_Connection_Helper.Wait_For_Socket_Writability(CONST TimeOut: Double): Boolean;

Trt_ServerSocket_Connection_Helper.Write_Everything_To_Socket

Writes the full memory-stream payload to the current connection socket.
Function Trt_ServerSocket_Connection_Helper.Write_Everything_To_Socket(CONST MS: ThMemoryStream): Boolean;

ThServerSocket.Stop

Stops listeners and closes active server-side resources managed by this instance.
Procedure ThServerSocket.Stop;

ThServerSocket.Connect_UDP_To

Creates a UDP socket connected to a remote endpoint (optionally bound to a specific NIC IP).
Function ThServerSocket.Connect_UDP_To(_IP: RawByteString; _Port: Integer; Bind_NIC_IP: RawByteString = ''): NativeUInt;

ThServerSocket.Open_UDP_Port

Opens a UDP listening/bound port on a specific local IP.
Function ThServerSocket.Open_UDP_Port(Bind_To_IP: RawByteString; _Port: Integer): Boolean;

ThServerSocket.Listen_To_TCP

Starts a TCP listener with selectable error policy (halt/popup behavior).
Function ThServerSocket.Listen_To_TCP(Bind_To_IP: RawByteString; _Port: Integer; HALT_On_Error, PopupError: Boolean): Boolean;

ThServerSocket.Listen_To_TLS_Chilkat

Starts a TLS listener using Chilkat socket stack/certificate flow.
Function ThServerSocket.Listen_To_TLS_Chilkat(Bind_To_IP: RawByteString; _Port: Integer; HALT_On_Error, PopupError: Boolean): Boolean;

ThServerSocket.Setup_Thread_Pool

Initializes thread-pool bounds used for asynchronous request dispatching.
Function ThServerSocket.Setup_Thread_Pool(MinAlive, MaxPool: Word): Boolean;

ThServerSocket.Current_Active_Threads

Returns the number of currently active request threads in the pool.
Function ThServerSocket.Current_Active_Threads: Integer;

ThServerSocket.Thread_Pool_Manager

Reference to the pool manager instance used by listener sockets.
When your application need to listen for multiple sockets (e.g. HTTP listening to 80 and 443), you want to work with ONE Thread Pool !!!
It is your responsibility to assign one socket to another - that had "Setup_Thread_Pool".
Property ThServerSocket.Thread_Pool_Manager: ThServerSocket Read FThread_Pool_Manager Write FThread_Pool_Manager;

ThServerSocket.OnTCP_NewConn

Raised when a new TCP connection is accepted.
Type
  TSocketEvent = Procedure (Socket: NativeUInt) OF Object;

Property ThServerSocket.OnTCP_NewConn: TSocketEvent Read FOnTCP_NewConn Write FOnTCP_NewConn;

ThServerSocket.OnUDP_DataArrived

Raised when datagram data arrives on the configured UDP port/socket.
Property ThServerSocket.OnUDP_DataArrived: TSocketEvent Read FOnUDP_DataArrived Write FOnUDP_DataArrived;

ThServerSocket.OnTLS_NewConn

Raised when a new TLS connection is accepted (Chilkat socket pointer callback).
Type
  TChilketSocketEvent = Procedure (ChilkatSocket: Pointer) OF Object;

Property ThServerSocket.OnTLS_NewConn: TChilketSocketEvent Read FonTLS_NewConn Write FonTLS_NewConn;

ThServerSocket.OnNew_Req_Thread

Raised when the thread-pool assigns a new connection/request to execution context.
Type
  ThServer_New_Req_Event = Procedure (VAR Conn: ThServerSocket_Connection_Data) OF Object;

Property ThServerSocket.OnNew_Req_Thread: ThServer_New_Req_Event Read FonNew_Req_Thread Write FonNew_Req_Thread;