Network Access
Get_Device_HostName
Returns the local host computer name using the system API.Function Get_Device_HostName: RawByteString;
Parameters
NoneReturn Value
Returns the host name of the device as a RawByteString.Query_Windows_DNS_For_IP
Queries the Windows DNS resolver (including cache) for A-records of a hostname.Function Query_Windows_DNS_For_IP(CONST _Host: RawByteString; All_IP_List: Boolean): RawByteString;
Parameters
- _Host: RawByteString; the hostname to resolve.
- All_IP_List: Boolean; if True, returns all resolved IPs; otherwise returns only the first one.
Return Value
Returns one or more resolved IPv4 addresses separated by CRLF if All_IP_List is True.Returns a single IP address string if All_IP_List is False.
Query_Real_DNS_For_MX
Sends a real DNS query to resolve the MX records of a domain (not using system cache).Function Query_Real_DNS_For_MX(CONST _Host: RawByteString): RawByteString;
Parameters
- _Host: RawByteString; domain name to query (e.g. 'gmail.com').
Return Value
Returns a string with MX record(s) if found, otherwise an empty string.Query_Real_DNS_For_A
Sends a direct DNS query (bypassing Windows cache) to resolve the A record(s) of a hostname.Function Query_Real_DNS_For_A(CONST _Host: RawByteString): RawByteString;
Parameters
- _Host: RawByteString; hostname to resolve (e.g. 'example.com').
Return Value
Returns one or more IP addresses from a real DNS query.Str_To_IP
Converts a string-formatted IPv4 address into its 32-bit cardinal form.Function Str_To_IP(StrAddress: RawByteString): Cardinal;
Parameters
- StrAddress: RawByteString; an IP address in dotted-decimal form (e.g. '192.168.0.1').
Return Value
Returns the numeric (cardinal) representation of the IP address.Returns 0 if conversion fails.
IP_To_Str
Converts a 32-bit numeric IP address into dotted-decimal string format.Function IP_To_Str(IPAddress: Cardinal; Opposite_Order: Boolean = False): RawByteString;
Parameters
- IPAddress: Cardinal; the IP address as a 32-bit value.
- Opposite_Order: Boolean; if True, reverses byte order (useful for little-endian conversions).
Return Value
Returns the IP as a dotted-decimal string.IS_Running_On_LAN_By_IP_Mask
Determines if the specified IP belongs to the same subnet as the local machine.Function IS_Running_On_LAN_By_IP_Mask(ServerIP: RawByteString): Boolean;
Parameters
- ServerIP: RawByteString; the IP address to compare with local network interfaces.
Return Value
Returns True if the given IP is in the same local network as this device.Returns False otherwise.
Connect_To_IP
Establishes a TCP or UDP socket connection to the specified IP and port.Optionally binds the socket to a local network interface and supports timeout control.
Function Connect_To_IP(_IP: RawByteString; _Port: Integer; CONST UDP: Boolean = False;
CONST Bind_NIC_IP: RawByteString = ''; TimeOut: Double = -1): NativeUInt;
Parameters
- _IP: RawByteString; the target IP address.
- _Port: Integer; the remote port to connect to.
- UDP: Boolean; if True, uses UDP protocol instead of TCP.
- Bind_NIC_IP: RawByteString; optional local interface IP to bind the socket.
- TimeOut: Double; timeout in seconds, or -1 for blocking mode.
Return Value
Returns the socket handle if the connection was established.Returns 0 if the connection fails.
HCloseSocket
Closes an open socket and optionally performs a graceful shutdown using linger mode.Procedure HCloseSocket(VAR _Socket: NativeUInt; Linger: Boolean = False);
Parameters
- _Socket: NativeUInt; the socket handle to close (will be set to 0 after closing).
- Linger: Boolean; if True, uses linger to wait for sending to complete.
GetPeerIP
Retrieves the IP address of the remote peer connected to the given socket.Function GetPeerIP(_Socket: NativeUInt): RawByteString;
Parameters
- _Socket: NativeUInt; the socket handle of the active connection.
Return Value
Returns the remote peer IP as a string.Returns an empty string if the connection is invalid or not connected.
Set_Blocking_Mode
Enables or disables blocking mode on the given socket.Function Set_Blocking_Mode(VAR _Socket: NativeUInt; Enabled: Boolean): Boolean;
Parameters
- _Socket: NativeUInt; the socket to configure.
- Enabled: Boolean; True for blocking, False for non-blocking.
Return Value
Returns True if the socket mode was changed successfully.Returns False on error.
Set_Big_Buffers
Sets large send and receive buffers on a socket to improve performance on large transfers.Function Set_Big_Buffers(VAR _Socket: NativeUInt): Boolean;
Parameters
- _Socket: NativeUInt; the socket handle to configure.
Return Value
Returns True if both buffer sizes were increased successfully.Returns False if setting failed.
Wait_For_Socket_Readability
Waits for the socket to become readable within a specified timeout.Function Wait_For_Socket_Readability(VAR _Socket: NativeUInt; CONST TimeOut: Double; CONST App_PM: Boolean): Boolean;
Parameters
- _Socket: NativeUInt; the socket to monitor.
- TimeOut: Double; timeout in seconds.
- App_PM: Boolean; if True, calls Application.ProcessMessages during wait.
Return Value
Returns True if the socket is ready for reading.Returns False if the wait times out.
Wait_For_Socket_Writability
Waits for the socket to become writable within a specified timeout.Function Wait_For_Socket_Writability(VAR _Socket: NativeUInt; CONST TimeOut: Double; CONST App_PM: Boolean): Boolean;
Parameters
- _Socket: NativeUInt; the socket to monitor.
- TimeOut: Double; timeout in seconds.
- App_PM: Boolean; if True, allows UI message pumping while waiting.
Return Value
Returns True if the socket is ready for writing.Returns False on timeout.
Check_Data_Waiting_On_RCV_Buffer
Checks how many bytes are waiting to be read from the socket's receive buffer.Function Check_Data_Waiting_On_RCV_Buffer(VAR _Socket: NativeUInt; VAR HowManyBytes: Cardinal): Boolean;
Parameters
- _Socket: NativeUInt; the socket to inspect.
- HowManyBytes: Cardinal; output parameter that returns the number of bytes available.
Return Value
Returns True if the query was successful.Returns False if the socket is closed or in error.
Check_Last_Socket_Error_And_Close_IF_Necessary
Closes the socket if the last operation failed due to a fatal socket error.Procedure Check_Last_Socket_Error_And_Close_IF_Necessary(VAR _Socket: NativeUInt);
Parameters
- _Socket: NativeUInt; socket to check and close if necessary.
HRecvBytes
Reads a specified number of bytes from a socket into a buffer with timeout and optional peeking.Function HRecvBytes(VAR _Socket: NativeUInt; VAR Buf; Bytes_To_Read: Integer; CONST TimeOut: Double = 0; CONST PeekData: Boolean = False): Boolean;
Parameters
- _Socket: NativeUInt; the socket to read from.
- Buf: VAR; the destination buffer to store data.
- Bytes_To_Read: Integer; number of bytes to receive.
- TimeOut: Double; optional timeout in seconds.
- PeekData: Boolean; if True, data is not removed from buffer (non-destructive read).
Return Value
Returns True if the exact number of bytes was received.Returns False on failure or timeout.
HRecvBytes2
Reads bytes from socket into buffer, returns actual count read, supports timeout and peeking.Function HRecvBytes2(VAR _Socket: NativeUInt; VAR Buf; Bytes_To_Read: Integer; CONST TimeOut: Double = 0; CONST PeekData: Boolean = False): Integer;
Parameters
- _Socket: NativeUInt; the socket handle to read from.
- Buf: VAR; the memory buffer to write to.
- Bytes_To_Read: Integer; requested number of bytes.
- TimeOut: Double; maximum wait time in seconds.
- PeekData: Boolean; if True, data is peeked without removing from buffer.
Return Value
Returns the number of bytes actually received (0 or more).Returns -1 on error.
HSend_String
Sends a raw byte string over a socket, including length prefix.Function HSend_String(VAR _Socket: NativeUInt; Text: RawByteString): Boolean;
Parameters
- _Socket: NativeUInt; the socket used for transmission.
- Text: RawByteString; the string data to send.
Return Value
Returns True if the full string and prefix were sent.Returns False on socket error.
HRecv_String
Receives a RawByteString over a socket including its length header.Function HRecv_String(VAR _Socket: NativeUInt; String_Max_Length: Word; CONST TimeOut: Double = 0): RawByteString;
Parameters
- _Socket: NativeUInt; the source socket handle.
- String_Max_Length: Word; maximum allowed length to receive (security check).
- TimeOut: Double; optional read timeout in seconds (0 = block).
Return Value
Returns the received string if successful.Returns an empty string if timeout or invalid input.
HRecv_WideString
Receives a UTF-16 wide string from a socket using prefixed length encoding.Function HRecv_WideString(VAR _Socket: NativeUInt; String_Max_Length: Word; CONST TimeOut: Double = 0): String;
Parameters
- _Socket: NativeUInt; socket handle to read from.
- String_Max_Length: Word; limit for safety (in characters).
- TimeOut: Double; time in seconds to wait for data.
Return Value
Returns a Unicode string if successful.Returns empty string on error or overflow.
Get_Buffers_Size
Returns the current socket buffer sizes (only for research or testing purposes).Function Get_Buffers_Size(VAR _Socket: NativeUInt): Boolean;
Parameters
- _Socket: NativeUInt; socket handle to query.
Return Value
Returns True if buffer sizes were successfully retrieved and logged.Returns False if socket is invalid or getsockopt fails.
Read_UTC_From_Server
Retrieves the current UTC time from a reliable internet time server (Google) and optionally sets the system clock.Function Read_UTC_From_Server(_And_Set_System_Clock, Log_Clock_Set: Boolean): TDateTime;
Parameters
- _And_Set_System_Clock: Boolean; if True, sets the local system time to the received UTC.
- Log_Clock_Set: Boolean; if True, logs the result of the system clock update to a file.
Return Value
Returns the UTC time retrieved from the server.Returns 0 if no valid time was retrieved.
Set_Time_From_INET_And_Set_Time_Zone
Updates the system clock from the internet and configures the local time zone bias and name.Function Set_Time_From_INET_And_Set_Time_Zone(Bias_Hours_From_UTC: Double; KeepTimeZoneName: Boolean): Boolean;
Parameters
- Bias_Hours_From_UTC: Double; desired time zone offset in hours (e.g. +3.0 for Israel).
- KeepTimeZoneName: Boolean; if True, retains the existing Windows time zone name (only adjusts bias).
Return Value
Returns True if both the time and time zone were successfully set.Returns False on failure to apply time or timezone settings.