TURN 客户端
在 Delphi/C++Builder 中与 TURN 服务器通信。分配中继传输地址、管理权限和通道,然后与对称 NAT 后面的对等方交换数据 — 符合 RFC 8656 标准。
在 Delphi/C++Builder 中与 TURN 服务器通信。分配中继传输地址、管理权限和通道,然后与对称 NAT 后面的对等方交换数据 — 符合 RFC 8656 标准。
TURN 客户端 — 支持 Allocate、CreatePermission、ChannelBind、Send / Indication / Data、Refresh,所有操作均使用 RFC 8656 长期凭据签名。
TsgcTURNClient
Windows, macOS, Linux, iOS, Android
Professional / Enterprise
设置 TURN 服务器/用户名/密码,调用 Allocate,然后对每个对等方调用 CreatePermission,再通过 Send / SendIndication 中继数据。
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();
符合 RFC 8656 标准的 TURN 客户端 — 当仅靠 STUN 无法穿透 NAT 时,为 WebRTC 提供中继层。
Allocate 发送带 REQUESTED-TRANSPORT(UDP、TCP)的分配请求并获取中继传输地址。Refresh 延长生命周期;Free 显式释放分配。
CreatePermission(peerIp) 注册允许中继转发数据报的对等方。权限在 5 分钟后自动过期 — 请按需刷新。
ChannelBind(channelNumber, peerEndpoint) 绕过 36 字节的 Send/Data 开销。组件自动编码 4 字节的 ChannelData 头部。
Authentication.UserName / Password 使用从 401 质询中提取的 realm 和 nonce 填充 MESSAGE-INTEGRITY。
在阻断 UDP 的环境中,将底层客户端的 Transport 设置为 TCP 或 TLS — 支持 RFC 6062 / 6056 传输选项。
TsgcRTCPeerConnection 将 TsgcTURNClient 作为其 IceServers 之一使用 — Allocate、CreatePermission 和 ChannelBind 的流程在后台透明进行。