Delphi TURN 클라이언트
Delphi/C++Builder에서 TURN 서버와 통신해요. 중계 전송 주소를 할당하고, 권한과 채널을 관리한 뒤 symmetric NAT 뒤에 있는 피어와 데이터를 주고받아요 — RFC 8656 준수예요.
Delphi/C++Builder에서 TURN 서버와 통신해요. 중계 전송 주소를 할당하고, 권한과 채널을 관리한 뒤 symmetric NAT 뒤에 있는 피어와 데이터를 주고받아요 — RFC 8656 준수예요.
TURN 클라이언트 — Allocate, CreatePermission, ChannelBind, Send / Indication / Data, Refresh를 RFC 8656에 따른 장기 자격 증명으로 모두 서명해요.
TURN 서버를 설정하고 자격 증명을 TURNOptions.Authentication에 넣은 뒤 Allocate를 호출하고, 피어마다 CreatePermission을 호출한 다음 SendIndication으로 데이터를 중계하세요.
uses
sgcP2P, sgcP2P_STUN_Classes, sgcP2P_STUN_Types, sgcP2P_TURN_Classes,
sgcSocket_Classes;
// TFormTURN은 FClient: TsgcTURNClient와 FLog: TStringList를 보유
procedure TFormTURN.StartAllocation;
begin
FClient := TsgcTURNClient.Create(nil);
FClient.Host := 'turn.example.com';
FClient.Port := 3478;
FClient.TURNOptions.Authentication.Credentials := stauLongTermCredential;
FClient.TURNOptions.Authentication.Username := 'alice';
FClient.TURNOptions.Authentication.Password := 'secret';
FClient.OnTURNAllocate := OnTURNAllocate;
FClient.Allocate;
end;
procedure TFormTURN.OnTURNAllocate(Sender: TObject;
const aSocket: TsgcSocketConnection;
const aMessage: TsgcSTUN_Message;
const aAllocation: TsgcTURN_ResponseAllocation);
begin
FLog.Add('relay: ' + aAllocation.RelayedIP + ':' +
IntToStr(aAllocation.RelayedPort));
// 릴레이는 권한을 부여한 피어에게만 전달함
FClient.CreatePermission('192.0.2.1');
FClient.SendIndication('192.0.2.1', 5000, 'hello via TURN');
end;
// includes: sgcP2P.hpp, sgcP2P_STUN_Types.hpp, sgcP2P_TURN_Classes.hpp
TsgcTURNClient *Client = new TsgcTURNClient(this);
Client->Host = "turn.example.com";
Client->Port = 3478;
Client->TURNOptions->Authentication->Credentials = stauLongTermCredential;
Client->TURNOptions->Authentication->Username = "alice";
Client->TURNOptions->Authentication->Password = "secret";
Client->OnTURNAllocate = OnTURNAllocate;
Client->Allocate();
타입이 지정된 RFC 8656 TURN 클라이언트 — STUN만으로는 NAT 통과가 실패할 때 WebRTC의 중계 계층 역할을 해요.
Allocate는 REQUESTED-TRANSPORT와 함께 Allocate 요청을 보내 중계 전송 주소를 얻고, 그 주소는 OnTURNAllocate에 aAllocation.RelayedIP와 RelayedPort로 도착해요. Refresh(lifetime)는 수명을 연장하고, Refresh(0)는 할당을 해제해요.
CreatePermission(peerIp)는 중계가 데이터그램을 전달할 피어를 등록해요. 권한은 5분 후에 자동으로 만료되므로, 필요에 따라 갱신해 주세요.
ChannelBind(peerIp, peerPort)는 36바이트 Send/Data 오버헤드를 우회해요. 컴포넌트가 채널 번호를 고르고 4바이트 ChannelData 헤더를 인코딩한 뒤, 바인딩 결과를 OnTURNChannelBind로 알려요.
TURNOptions.Authentication.Username과 Password는 401 챌린지에서 가져온 realm과 nonce를 사용해 MESSAGE-INTEGRITY를 채워요. Credentials로 단기와 장기 중 하나를 선택해요.
Transport := stunTCP는 UDP를 차단하는 네트워크를 위해 제어 채널을 TCP로 옮겨요. RFC 6062가 정의한 경로예요. 그다음에는 TURNOptions.AutoRefresh가 할당과 권한, 채널을 알아서 유지해요.
TsgcICEClient는 TURNClient 속성으로 TURN 클라이언트를 구동하고, TsgcRTCPeerConnection은 RTCOptions.ICEServers의 turn: 항목에서 할당을 받아요. Allocate와 CreatePermission, ChannelBind 순서는 자동으로 처리돼요.
컴포넌트 레퍼런스로 바로 이동하고, 바로 실행할 수 있는 데모 프로젝트를 받아보고, 체험판을 다운로드하세요.
| 온라인 도움말 — TsgcTURNClient 이 컴포넌트의 전체 속성, 메서드, 이벤트 레퍼런스예요. | 열기 | |
| 데모 프로젝트 — Demos\35.P2P\03.TURN 바로 실행할 수 있는 예제 프로젝트예요. sgcWebSockets 패키지에 포함되어 있으니 아래에서 체험판을 다운로드해 보세요. | 열기 | |
| 기술 문서 (PDF) 이 컴포넌트의 기능, 빠른 시작, Delphi 및 C++ Builder 코드 샘플, 출처 참고 자료예요. | 열기 | |
| 사용자 설명서 (PDF) 라이브러리의 모든 컴포넌트를 다루는 종합 설명서예요. | 열기 |