TURN Server

Run your own TURN (RFC 8656) server in Delphi. Allocate relayed transport addresses for clients that cannot establish a peer-to-peer path, with long-term credentials and per-allocation quotas.

TsgcTURNServer

A self-hosted TURN server — processes Allocate / CreatePermission / ChannelBind / Send / Refresh / Data, manages allocations and bandwidth, validates long-term credentials.

Component class

TsgcTURNServer

Protocol

TURN (RFC 8656)

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Enterprise

Drop, set realm, hand out credentials

Set Port + Realm, supply per-user passwords via OnTURNAuthenticate, Active := True — your server now allocates relays for any RFC 8656 client.

uses
  sgcP2P;

var
  TURNServer: TsgcTURNServer;
begin
  TURNServer := TsgcTURNServer.Create(nil);
  TURNServer.Port  := 3478;
  TURNServer.Realm := 'turn.example.com';

  TURNServer.OnTURNAuthenticate := procedure(Sender: TObject;
    const aUsername: string; var aPassword: string;
    var Accept: Boolean)
  begin
    aPassword := LookupPassword(aUsername);
    Accept    := aPassword <> '';
  end;

  TURNServer.Active := True;
end;
// uses: sgcP2P
TsgcTURNServer *TURNServer = new TsgcTURNServer(this);
TURNServer->Port  = 3478;
TURNServer->Realm = "turn.example.com";
TURNServer->Active = true;

What's inside

A self-hosted relay — lets your WebRTC and ICE deployments stop depending on third-party TURN providers.

Allocate / Refresh / Free

Honours Allocate requests with REQUESTED-TRANSPORT, picks a free relay port and tracks lifetime. Refresh extends the allocation; the server tears it down on expiry.

CreatePermission / ChannelBind

Tracks per-allocation peer permissions and channel bindings. Drops Send/Data frames for peers that have not been permissioned per RFC 8656 §9.

Send / Data / ChannelData

Both 36-byte Send / Data envelopes and 4-byte ChannelData frames are supported. The relay forwards datagrams between the relayed-transport-address and the bound peer.

Long-term credentials

OnTURNAuthenticate exposes the username; you return the password — the server validates MESSAGE-INTEGRITY and rotates nonces automatically.

Quotas

Set Quota.MaxAllocationsPerUser, Quota.MaxBandwidthKbps, Quota.AllocationLifetime to bound abuse. OnQuotaExceeded reports rejections.

TURN over TCP / TLS

Toggle the underlying server's transport — UDP, TCP and TLS over TCP are all supported. WebRTC clients pick whichever traverses their NAT.

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 — TsgcTURNServer Full property, method and event reference for this component.
Demo Project — Demos\35.P2P\03.TURN 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.

TURN Server Frequently Asked Questions

Common questions about running a self-hosted TURN relay in Delphi and C++ Builder.

Drop a TsgcTURNServer component, set Port and Realm, supply per-user passwords from the OnTURNAuthenticate event, then set Active := True. The server then handles Allocate, CreatePermission, ChannelBind, Send, Refresh and Data for any RFC 8656 client, relaying datagrams between the relayed transport address and the bound peer.
It implements TURN per RFC 8656, validating long-term credentials with MESSAGE-INTEGRITY and rotating nonces automatically. It also references RFC 6062 for TURN over TCP allocations and RFC 8489 for the underlying STUN message format, and supports UDP, TCP and TLS over TCP transports.
No. TsgcTURNServer is a self-hosted relay you embed in your own Delphi or C++ Builder application, so your WebRTC and ICE deployments can stop depending on third-party TURN providers or a separate coturn install. Per-allocation quotas (max allocations per user, bandwidth and lifetime) bound abuse, with OnQuotaExceeded reporting rejections.
The TURN server is part of the sgcWebSockets Enterprise edition and supports Delphi 7 through the latest Delphi release and the matching C++ Builder versions, on Windows, macOS, Linux, iOS and Android. Download the free trial to stand up a TURN relay in your own project.

Ready to Run Your Own TURN Server?

Download the free trial and stand up a TURN relay in Delphi.