TURN 服务器
在 Delphi 中运行您自己的 TURN(RFC 8656)服务器。为无法建立点对点路径的客户端分配中继传输地址,支持长期凭据和按分配配额管理。
在 Delphi 中运行您自己的 TURN(RFC 8656)服务器。为无法建立点对点路径的客户端分配中继传输地址,支持长期凭据和按分配配额管理。
自托管 TURN 服务器 — 处理 Allocate / CreatePermission / ChannelBind / Send / Refresh / Data,管理分配和带宽,验证长期凭据。
设置 Port + Realm,通过 OnTURNAuthenticate 提供每用户密码,Active := True — 服务器即可为任何 RFC 8656 客户端分配中继。
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;
自托管中继服务器 — 让您的 WebRTC 和 ICE 部署不再依赖第三方 TURN 提供商。
响应带 REQUESTED-TRANSPORT 的分配请求,选择空闲中继端口并追踪生命周期。Refresh 延长分配;服务器在过期时自动销毁。
追踪每个分配的对等方权限和通道绑定。按照 RFC 8656 §9,丢弃未经授权的对等方的 Send/Data 帧。
同时支持 36 字节的 Send/Data 包封和 4 字节的 ChannelData 帧。中继在中继传输地址和绑定对等方之间转发数据报。
OnTURNAuthenticate 暴露用户名;您返回密码 — 服务器验证 MESSAGE-INTEGRITY 并自动轮换 nonce。
设置 Quota.MaxAllocationsPerUser、Quota.MaxBandwidthKbps、Quota.AllocationLifetime 以限制滥用。OnQuotaExceeded 报告拒绝情况。
切换底层服务器的传输方式 — UDP、TCP 和 TCP 上的 TLS 均受支持。WebRTC 客户端会选择能穿透其 NAT 的传输方式。