TsgcSTUNClientMethods › WriteData

WriteData Method

Advanced: sends raw bytes over the STUN client socket, either to the connected peer or to an explicit IP/port pair.

Overloads

Overload 1

Syntax

procedure WriteData(const aBytes: TBytes);

Parameters

NameTypeDescription
aBytesconst TBytesRaw bytes to send; normally a pre-built STUN message.

Remarks

Sends aBytes as-is to the currently configured STUN server (see Host/Port). Use this overload to transmit a custom STUN or TURN message that you have assembled manually.

Example

var
  vBytes: TBytes;
begin
  vBytes := BuildCustomStunMessage;
  oSTUN.WriteData(vBytes);
end;

Overload 2

Syntax

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

Parameters

NameTypeDescription
aIPAddressconst stringDestination IP address (IPv4 or IPv6, matching IPVersion).
aPortWordDestination UDP/TCP port.
aBytesconst TBytesRaw bytes to send to the target endpoint.

Remarks

Sends aBytes to an arbitrary host:port pair instead of the one defined by Host/Port. Typically used in STUN check scenarios where the server replies from a different address (RFC 5780 NAT Behavior Discovery) or when reusing the same socket to reach several STUN peers.

Example

var
  vBytes: TBytes;
begin
  vBytes := BuildCustomStunMessage;
  oSTUN.WriteData('192.0.2.10', 3478, vBytes);
end;

Back to Methods