TsgcUDPCLientMethods › WriteData

WriteData Method

Sends a single UDP datagram to an explicit destination address and port.

Overloads

Overload 1

Syntax

procedure WriteData(const aIPAddress: string; aPort: Word; const aValue: string);

Parameters

NameTypeDescription
aIPAddressconst stringDestination IPv4/IPv6 address or DNS name. Overrides the Host property for this call only.
aPortWordDestination UDP port in the range 1 to 65535. Overrides the Port property for this call only.
aValueconst stringText payload. Encoded as UTF-8 bytes before being transmitted.

Remarks

Sends the string payload as a single UDP datagram to the specified address, without altering the Host/Port properties. This overload is convenient for broadcasting text messages, replying to a previously received peer, or targeting multiple hosts from one client instance. When DTLS is enabled, the datagram is encrypted with the currently cached DTLS session.

Example

oClient.WriteData('192.168.1.10', 5000, 'hello');

Overload 2

Syntax

procedure WriteData(const aIPAddress: string; aPort: Word; const aValue: TBytes);

Parameters

NameTypeDescription
aIPAddressconst stringDestination IPv4/IPv6 address or DNS name. Overrides the Host property for this call only.
aPortWordDestination UDP port in the range 1 to 65535. Overrides the Port property for this call only.
aValueconst TBytesRaw binary payload sent verbatim inside the UDP datagram.

Remarks

Sends a binary buffer as a single UDP datagram to the specified address and port. Use this form when the payload is not text (for example, serialized protocol frames, audio samples or media) so that no character-set conversion is applied. Datagram size should be kept below the path MTU (typically 1472 bytes on IPv4 Ethernet) to avoid IP fragmentation.

Example

var vBytes: TBytes;
begin
  vBytes := TEncoding.UTF8.GetBytes('ping');
  oClient.WriteData('192.168.1.10', 5000, vBytes);
end;

Back to Methods