TURN Client

Talk to a TURN server from Delphi/C++Builder. Allocate relayed transport addresses, manage permissions and channels, then exchange data with peers behind symmetric NAT — per RFC 8656.

TsgcTURNClient

TURN client — Allocate, CreatePermission, ChannelBind, Send / Indication / Data, Refresh, all signed with long-term credentials per RFC 8656.

Component class

TsgcTURNClient

Protocol

TURN (RFC 8656)

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Professional / Enterprise

Allocate, permission, send

Set TURN server / username / password, call Allocate, then CreatePermission for each peer and Send / SendIndication to relay data.

uses
  sgcP2P;

var
  TURN: TsgcTURNClient;
begin
  TURN := TsgcTURNClient.Create(nil);
  TURN.Host := 'turn.example.com';
  TURN.Port := 3478;
  TURN.Authentication.UserName := 'alice';
  TURN.Authentication.Password := 'secret';

  TURN.OnTURNAllocated := procedure(Sender: TObject;
    const aRelayedAddress, aRelayedPort: string)
  begin
    Memo1.Lines.Add('relay: ' + aRelayedAddress + ':' + aRelayedPort);
    TURN.CreatePermission('192.0.2.1');
    TURN.SendIndication('192.0.2.1', 5000, 'hello via TURN');
  end;

  TURN.Allocate;
end;
// uses: sgcP2P
TsgcTURNClient *TURN = new TsgcTURNClient(this);
TURN->Host = "turn.example.com";
TURN->Port = 3478;
TURN->Authentication->UserName = "alice";
TURN->Authentication->Password = "secret";
TURN->Allocate();

What's inside

A typed RFC 8656 TURN client — the relay layer for WebRTC when STUN-only NAT traversal fails.

Allocate / Refresh

Allocate sends Allocate request with REQUESTED-TRANSPORT (UDP, TCP) and obtains a relayed transport address. Refresh extends the lifetime; Free deallocates explicitly.

CreatePermission

CreatePermission(peerIp) registers a peer whose datagrams the relay will forward. Permissions auto-expire after 5 minutes — refresh as needed.

ChannelBind

ChannelBind(channelNumber, peerEndpoint) bypasses the 36-byte Send/Data overhead. The component encodes the 4-byte ChannelData header automatically.

Long-term credentials

Authentication.UserName / Password populate MESSAGE-INTEGRITY using the realm and nonce extracted from the 401 challenge.

TURN over TCP/TLS

Set the underlying client's Transport to TCP or TLS for environments that block UDP — RFC 6062 / 6056 transport choices are supported.

WebRTC ready

TsgcRTCPeerConnection consumes TsgcTURNClient as one of its IceServers — the Allocate, CreatePermission and ChannelBind dance happens transparently.

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 — TsgcTURNClient 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.

Ready to Use TURN from Delphi?

Download the free trial and add TURN-based relaying to your Delphi applications.