TURN Client | Channels

Channels provide a way for the TURN Client and Server to send application data using ChannelData messages, which have less overhead than Send and Data Indications.

 

Before use ChannelData messages to exchange data between peers, the TURN client must create a new channel, to do this, just call the method ChannelBind passing the Peer IP Address and Port as parameters.

 

If the TURN server can bind a new channel, the TURN client will receive a successful response OnTURNChannelBind event.

 


oTURN.ChannelBind('80.147.23.157', 5000);

procedure OnTURNChannelBind(Sender: TObject; const aSocket: TsgcSocketConnection; 
  const aMessage: TsgcSTUN_Message; const aChannelBind: TsgcTURN_ResponseChannelBind);
begin
  DoLog('#Channel Bind: ' + IntToStr(aChannelBind.Channel));
end;

A channel binding lasts for 10 minutes unless refreshed. To refresh a channel just call ChannelBind method again.

 

When the TURN client receives a new ChannelMessage, the event OnTURNChannelData is called.

 


procedure OnTURNChannelData(Sender: TObject; const aSocket: TsgcSocketConnection; 
  const aChannelData: TsgcTURNChannelData);
begin
  DoLog('#Channel Data: [' + IntToStr(aChannelData.ChannelID) + '] ' + 
    sgcGetStringFromBytes(aChannelData.Data));
end;