STUN Client
Discover your reflexive endpoint behind NAT with a typed STUN (RFC 8489) client. Used as the bootstrap step for ICE candidate gathering and WebRTC.
Discover your reflexive endpoint behind NAT with a typed STUN (RFC 8489) client. Used as the bootstrap step for ICE candidate gathering and WebRTC.
STUN client — Binding requests, XOR-MAPPED-ADDRESS extraction, MESSAGE-INTEGRITY / FINGERPRINT support, retransmission timer per RFC 8489.
TsgcSTUNClient
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
Set the STUN server host/port, call SendBindingRequest, then read MappedAddress / MappedPort from OnSTUNMappedAddress.
uses
sgcP2P;
var
STUN: TsgcSTUNClient;
begin
STUN := TsgcSTUNClient.Create(nil);
STUN.Host := 'stun.l.google.com';
STUN.Port := 19302;
STUN.OnSTUNMappedAddress := procedure(Sender: TObject;
const aMappedAddress, aMappedPort: string)
begin
Memo1.Lines.Add('public: ' + aMappedAddress + ':' + aMappedPort);
end;
STUN.SendBindingRequest;
end;
// uses: sgcP2P
TsgcSTUNClient *STUN = new TsgcSTUNClient(this);
STUN->Host = "stun.l.google.com";
STUN->Port = 19302;
STUN->SendBindingRequest();
A typed RFC 8489 STUN client with the message-integrity and fingerprint extensions used by ICE.
SendBindingRequest sends the STUN 0x0001 message; the response surfaces in OnSTUNMappedAddress with the parsed XOR-MAPPED-ADDRESS attribute.
Set Authentication.UserName / Password and the component computes MESSAGE-INTEGRITY (HMAC-SHA1 / HMAC-SHA256). The realm and nonce are extracted from the 401 challenge response.
STUN over UDP requires application-layer retransmission. The component implements the standard back-off (RTO / Rc / Rm) per RFC 8489 §6.2.1.
XOR-MAPPED-ADDRESS comes back in either family — the component decodes both and stores the canonical text form in MappedAddress.
Drive multiple TsgcSTUNClient instances against several STUN servers to gather server-reflexive ICE candidates — one per local interface.
Uses TsgcUDPClient internally; the local-port binding is configurable so STUN, ICE and the data path can share an endpoint when required.
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.
| Online Help — TsgcSTUNClient Full property, method and event reference for this component. | Open | |
| Demo Project — Demos\35.P2P\02.STUN Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |