TsgcUDPCLient › Methods › WriteData
Sends a single UDP datagram to an explicit destination address and port.
procedure WriteData(const aIPAddress: string; aPort: Word; const aValue: string);
| Name | Type | Description |
|---|---|---|
aIPAddress | const string | Destination IPv4/IPv6 address or DNS name. Overrides the Host property for this call only. |
aPort | Word | Destination UDP port in the range 1 to 65535. Overrides the Port property for this call only. |
aValue | const string | Text payload. Encoded as UTF-8 bytes before being transmitted. |
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.
oClient.WriteData('192.168.1.10', 5000, 'hello');
procedure WriteData(const aIPAddress: string; aPort: Word; const aValue: TBytes);
| Name | Type | Description |
|---|---|---|
aIPAddress | const string | Destination IPv4/IPv6 address or DNS name. Overrides the Host property for this call only. |
aPort | Word | Destination UDP port in the range 1 to 65535. Overrides the Port property for this call only. |
aValue | const TBytes | Raw binary payload sent verbatim inside the UDP datagram. |
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.
var vBytes: TBytes;
begin
vBytes := TEncoding.UTF8.GetBytes('ping');
oClient.WriteData('192.168.1.10', 5000, vBytes);
end;