Delphi STUN Server
Run your own STUN (RFC 8489) server in Delphi. Answer binding requests with the canonical XOR-MAPPED-ADDRESS reply — useful in private networks, on-premise deployments and ICE bootstrapping.
Run your own STUN (RFC 8489) server in Delphi. Answer binding requests with the canonical XOR-MAPPED-ADDRESS reply — useful in private networks, on-premise deployments and ICE bootstrapping.
A typed RFC 8489 STUN server — processes Binding / Indication messages, replies with XOR-MAPPED-ADDRESS, optionally enforces MESSAGE-INTEGRITY for long-term auth.
TsgcSTUNServer
Windows, macOS, Linux, iOS, Android
Professional / Enterprise
Set Port (default 3478), Active := True — your server now answers Binding requests with the canonical RFC 8489 XOR-MAPPED-ADDRESS reply.
uses
sgcP2P, sgcP2P_STUN_Classes;
// TFormSTUNServer holds FServer: TsgcSTUNServer and the handler
procedure TFormSTUNServer.StartServer;
begin
FServer := TsgcSTUNServer.Create(nil);
FServer.Port := 3478;
// optional: long term credentials
FServer.STUNOptions.Authentication.Enabled := True;
FServer.STUNOptions.Authentication.LongTermCredentials.Enabled := True;
FServer.STUNOptions.Authentication.LongTermCredentials.Realm :=
'example.com';
FServer.OnSTUNRequestAuthorization := OnSTUNRequestAuthorization;
FServer.Active := True;
end;
procedure TFormSTUNServer.OnSTUNRequestAuthorization(Sender: TObject;
const aRequest: TsgcSTUN_Message;
const aUsername, aRealm: string;
var Password: string);
begin
// return the password of that user, empty rejects the request
Password := LookupPassword(aUsername);
end;
// includes: sgcP2P.hpp, sgcP2P_STUN_Classes.hpp
TsgcSTUNServer *Server = new TsgcSTUNServer(this);
Server->Port = 3478;
Server->STUNOptions->Authentication->Enabled = true;
Server->STUNOptions->Authentication->LongTermCredentials->Enabled = true;
Server->STUNOptions->Authentication->LongTermCredentials->Realm = "example.com";
Server->OnSTUNRequestAuthorization = OnSTUNRequestAuthorization;
Server->Active = true;
A self-hosted STUN server — ideal for on-premise WebRTC deployments and private-cloud testing.
Inbound Binding requests are answered with XOR-MAPPED-ADDRESS, MAPPED-ADDRESS (legacy) and FINGERPRINT — matching the standard RFC 8489 reply shape.
Toggle STUNOptions.Authentication.Enabled to require MESSAGE-INTEGRITY and set the realm on LongTermCredentials.Realm. OnSTUNRequestAuthorization hands you the username and the realm, and you return the matching password.
STUNOptions.BindingAttributes switches the legacy RFC 3489 MAPPED-ADDRESS, OTHER-ADDRESS, RESPONSE-ORIGIN and SOURCE-ADDRESS on or off, and AlternateServer answers 300 Try Alternate with the server you name.
Bind to either family or dual-stack via IPVersion. The XOR-MAPPED-ADDRESS reply uses the family of the inbound transport.
LongTermCredentials.StaleNonce sets how long a nonce stays valid. Once it expires the server answers 438 Stale Nonce with a fresh one, which is what RFC 8489 §9.2 asks for.
OnSTUNRequestSuccess and OnSTUNRequestError hand you the request and the response the server is about to send, with a var Accept you can clear. LogFile writes the raw exchange to disk.
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.
| Online Help — TsgcSTUNServer 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 |
Common questions about running a self-hosted STUN server in Delphi and C++ Builder.
TsgcSTUNServer component, set Port (default 3478) and set Active := True. The server then answers inbound Binding requests with the canonical XOR-MAPPED-ADDRESS reply. Optionally enable Authentication and handle OnSTUNRequestAuthorization to require MESSAGE-INTEGRITY with long-term credentials.TsgcSTUNServer is a self-hosted STUN server you embed directly in your own Delphi or C++ Builder application, so you do not need to deploy and operate a separate coturn instance. It is ideal for private networks, on-premise WebRTC deployments and ICE bootstrapping under your own control.