Servidor TURN para Delphi
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.
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.
Um servidor TURN self-hosted — processa Allocate / CreatePermission / ChannelBind / Send / Refresh / Data, gerencia as alocações e o tempo de vida delas, valida credenciais de longo prazo.
TsgcTURNServer
Windows, macOS, Linux, iOS, Android
Enterprise
Defina Port e o realm em TURNOptions.Authentication.LongTermCredentials, forneça as senhas por usuário via OnSTUNRequestAuthorization, Active := True — o seu servidor agora aloca relays para qualquer cliente RFC 8656.
uses
sgcP2P, sgcP2P_STUN_Classes;
// TFormTURNServer mantém FServer: TsgcTURNServer e o handler
procedure TFormTURNServer.StartServer;
begin
FServer := TsgcTURNServer.Create(nil);
FServer.Port := 3478;
FServer.TURNOptions.Authentication.Enabled := True;
FServer.TURNOptions.Authentication.LongTermCredentials.Enabled := True;
FServer.TURNOptions.Authentication.LongTermCredentials.Realm :=
'turn.example.com';
// limite o abuso: alocações por usuário e tempo de vida máximo
FServer.TURNOptions.Allocation.MaxUserAllocations := 4;
FServer.TURNOptions.Allocation.MaxLifeTime := 3600;
FServer.OnSTUNRequestAuthorization := OnSTUNRequestAuthorization;
FServer.Active := True;
end;
procedure TFormTURNServer.OnSTUNRequestAuthorization(Sender: TObject;
const aRequest: TsgcSTUN_Message;
const aUsername, aRealm: string;
var Password: string);
begin
// retorne a senha desse usuário, vazio rejeita a requisição
Password := LookupPassword(aUsername);
end;
// includes: sgcP2P.hpp, sgcP2P_STUN_Classes.hpp
TsgcTURNServer *Server = new TsgcTURNServer(this);
Server->Port = 3478;
Server->TURNOptions->Authentication->Enabled = true;
Server->TURNOptions->Authentication->LongTermCredentials->Enabled = true;
Server->TURNOptions->Authentication->LongTermCredentials->Realm = "turn.example.com";
Server->TURNOptions->Allocation->MaxUserAllocations = 4;
Server->OnSTUNRequestAuthorization = OnSTUNRequestAuthorization;
Server->Active = true;
A self-hosted relay — lets your WebRTC and ICE deployments stop depending on third-party TURN providers.
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.
Tracks per-allocation peer permissions and channel bindings. Drops Send/Data frames for peers that have not been permissioned per RFC 8656 §9.
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.
TURNOptions.Authentication.LongTermCredentials carrega o realm, e OnSTUNRequestAuthorization expõe o username e esse realm para que você retorne a senha. O servidor valida o MESSAGE-INTEGRITY e faz a rotação dos nonces por conta própria.
TURNOptions.Allocation.MaxUserAllocations limita quantos relays um usuário obtém, DefaultLifeTime e MaxLifeTime limitam quanto tempo cada um vive, e MinPort / MaxPort / RelayIP fixam a faixa de relay. Um usuário acima do limite recebe 486 Allocation Quota Reached.
OnTURNBeforeAllocate lhe entrega o endereço solicitante com um var Reject, e OnTURNBeforeRelayIndication e OnTURNBeforeRelayChannelData fazem o mesmo para cada datagrama repassado. OnTURNCreateAllocation e OnTURNDeleteAllocation acompanham as que continuam ativas.
Acesse a referência do componente, pegue o projeto demo pronto para executar e baixe a versão de avaliação.
| Ajuda online — TsgcTURNServer Referência completa de propriedades, métodos e eventos deste componente. | Abrir | |
| Projeto demo — Demos\35.P2P\03.TURN Exemplo pronto para executar. Acompanha o pacote sgcWebSockets — baixe a versão de avaliação abaixo. | Abrir | |
| Documento técnico (PDF) Recursos, início rápido, exemplos de código para Delphi & C++ Builder e referências de fontes primárias — somente deste componente. | Abrir | |
| Manual do usuário (PDF) Manual completo cobrindo todos os componentes da biblioteca. | Abrir |
Dúvidas comuns sobre executar um relay TURN auto-hospedado em Delphi e C++ Builder.
TsgcTURNServer, defina Port e Realm, forneça senhas por usuário a partir do evento OnSTUNRequestAuthorization e, em seguida, defina Active := True. O servidor então trata Allocate, CreatePermission, ChannelBind, Send, Refresh e Data para qualquer client RFC 8656, retransmitindo datagramas entre o endereço de transporte retransmitido e o peer vinculado.TsgcTURNServer é um relay auto-hospedado que você incorpora no seu próprio aplicativo Delphi ou C++ Builder, de modo que suas implantações WebRTC e ICE podem deixar de depender de provedores TURN de terceiros ou de uma instalação coturn separada. Cotas por alocação (máximo de alocações por usuário, largura de banda e tempo de vida) limitam o abuso, com OnQuotaExceeded reportando as rejeições.