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.

TsgcSTUNServer

A typed RFC 8489 STUN server — processes Binding / Indication messages, replies with XOR-MAPPED-ADDRESS, optionally enforces MESSAGE-INTEGRITY for long-term auth.

Component class

TsgcSTUNServer

Protocol

STUN (RFC 8489)

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Enterprise

Drop, set port, you have a STUN endpoint

Set Port (default 3478), Active := True — your server now answers Binding requests with the canonical RFC 8489 XOR-MAPPED-ADDRESS reply.

uses
  sgcP2P;

var
  STUNServer: TsgcSTUNServer;
begin
  STUNServer := TsgcSTUNServer.Create(nil);
  STUNServer.Port := 3478;

  // optional: long-term credentials
  STUNServer.Authentication.Enabled  := True;
  STUNServer.Authentication.Realm    := 'example.com';
  STUNServer.OnSTUNAuthenticate := procedure(Sender: TObject;
    const aUsername: string; var aPassword: string;
    var Accept: Boolean)
  begin
    aPassword := LookupPassword(aUsername);
    Accept    := aPassword <> '';
  end;

  STUNServer.Active := True;
end;
// uses: sgcP2P
TsgcSTUNServer *STUNServer = new TsgcSTUNServer(this);
STUNServer->Port = 3478;
STUNServer->Active = true;

What's inside

A self-hosted STUN server — ideal for on-premise WebRTC deployments and private-cloud testing.

Binding request handler

Inbound Binding requests are answered with XOR-MAPPED-ADDRESS, MAPPED-ADDRESS (legacy) and FINGERPRINT — matching the standard RFC 8489 reply shape.

Long-term / short-term auth

Toggle Authentication.Enabled to require MESSAGE-INTEGRITY. OnSTUNAuthenticate exposes the username from the request so you return the matching password from your store.

Per-IP rate limit

Combine with TsgcWSRateLimiter to throttle inbound STUN requests per source IP — useful protection against amplification abuse.

IPv4 / IPv6

Bind to either family or dual-stack via IPVersion. The XOR-MAPPED-ADDRESS reply uses the family of the inbound transport.

TLS over TCP (RFC 8489 §5)

For the STUN-over-TLS variant configure the underlying TCP listener with SSL options — useful when UDP is blocked at the network egress.

Diagnostics

OnSTUNRequest / OnSTUNResponse log every transaction including Method, MessageType and the parsed attribute list — great for debugging deployments.

Specifications & references

Authoritative sources for the protocol this component implements.

Documentation & Demos

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.
Demo Project — Demos\35.P2P\02.STUN Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Run Your Own STUN Server?

Download the free trial and stand up a STUN endpoint in Delphi.