Delphi TURN 서버
Delphi에서 자체 TURN(RFC 8656) 서버를 실행하세요. P2P 경로를 설정할 수 없는 클라이언트에게 중계 전송 주소를 할당하고, 장기 자격 증명과 할당별 할당량을 지원해요.
Delphi에서 자체 TURN(RFC 8656) 서버를 실행하세요. P2P 경로를 설정할 수 없는 클라이언트에게 중계 전송 주소를 할당하고, 장기 자격 증명과 할당별 할당량을 지원해요.
자체 호스팅 TURN 서버 — Allocate / CreatePermission / ChannelBind / Send / Refresh / Data를 처리하고, 할당과 그 수명을 관리하며, 장기 자격 증명을 검증해요.
Port를 설정하고 렐름은 TURNOptions.Authentication.LongTermCredentials에 지정한 뒤, OnSTUNRequestAuthorization로 사용자별 비밀번호를 제공하고 Active := True 하세요 — 이제 서버가 모든 RFC 8656 클라이언트에 중계를 할당해요.
uses
sgcP2P, sgcP2P_STUN_Classes;
// TFormTURNServer는 FServer: TsgcTURNServer와 핸들러를 보유
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';
// 오용 방지: 사용자별 할당 수와 최대 수명 제한
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
// 해당 사용자의 비밀번호를 반환, 빈 값이면 요청을 거부
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;
자체 호스팅 중계 서버 — WebRTC 및 ICE 배포가 서드파티 TURN 공급자에 의존하지 않도록 해줘요.
REQUESTED-TRANSPORT가 포함된 Allocate 요청을 처리하고 사용 가능한 중계 포트를 선택해 수명을 추적해요. Refresh는 할당을 연장하며, 만료 시 서버가 할당을 정리해요.
할당별 피어 권한과 채널 바인딩을 추적해요. RFC 8656 §9에 따라 권한이 부여되지 않은 피어의 Send/Data 프레임은 폐기해요.
36바이트 Send / Data 봉투와 4바이트 ChannelData 프레임을 모두 지원해요. 중계가 relayed-transport-address와 바인딩된 피어 사이에서 데이터그램을 전달해요.
TURNOptions.Authentication.LongTermCredentials에 렐름이 담기고, OnSTUNRequestAuthorization가 사용자명과 그 렐름을 전달하므로 비밀번호를 반환하면 돼요. 서버가 MESSAGE-INTEGRITY를 검증하고 논스도 알아서 회전시켜요.
TURNOptions.Allocation.MaxUserAllocations는 사용자 한 명이 받을 수 있는 중계 수를 제한하고, DefaultLifeTime과 MaxLifeTime은 각 중계의 수명을 제한하며, MinPort / MaxPort / RelayIP는 중계 포트 범위를 고정해요. 한도를 넘은 사용자는 486 Allocation Quota Reached를 받아요.
OnTURNBeforeAllocate는 요청한 주소를 var Reject와 함께 전달하고, OnTURNBeforeRelayIndication과 OnTURNBeforeRelayChannelData는 중계되는 모든 데이터그램에 대해 같은 일을 해요. OnTURNCreateAllocation과 OnTURNDeleteAllocation으로 살아 있는 할당을 추적해요.
컴포넌트 레퍼런스로 바로 이동하고, 바로 실행할 수 있는 데모 프로젝트를 받아보고, 체험판을 다운로드하세요.
| 온라인 도움말 — TsgcTURNServer 이 컴포넌트의 전체 속성, 메서드, 이벤트 레퍼런스예요. | 열기 | |
| 데모 프로젝트 — Demos\35.P2P\03.TURN 바로 실행할 수 있는 예제 프로젝트예요. sgcWebSockets 패키지에 포함되어 있으니 아래에서 체험판을 다운로드해 보세요. | 열기 | |
| 기술 문서 (PDF) 이 컴포넌트의 기능, 빠른 시작, Delphi 및 C++ Builder 코드 샘플, 출처 참고 자료예요. | 열기 | |
| 사용자 설명서 (PDF) 라이브러리의 모든 컴포넌트를 다루는 종합 설명서예요. | 열기 |
Delphi 및 C++ Builder에서 자체 호스팅 TURN 릴레이를 운영하는 것에 대해 자주 묻는 질문이에요.
TsgcTURNServer 컴포넌트를 추가하고, Port와 Realm을 설정하고, OnSTUNRequestAuthorization 이벤트에서 사용자별 비밀번호를 제공한 다음 Active := True로 설정하세요. 그러면 서버가 모든 RFC 8656 클라이언트에 대해 Allocate, CreatePermission, ChannelBind, Send, Refresh, Data를 처리하여, 릴레이된 전송 주소와 바인딩된 피어 사이에서 데이터그램을 중계해요.TsgcTURNServer는 직접 Delphi 또는 C++ Builder 애플리케이션에 내장하는 자체 호스팅 릴레이이므로, WebRTC 및 ICE 배포가 타사 TURN 제공업체나 별도의 coturn 설치에 의존하지 않을 수 있어요. 할당별 할당량(사용자당 최대 할당 수, 대역폭, 수명)으로 남용을 제한하며, OnQuotaExceeded가 거부를 보고해요.