TURN Protocol allows to use a Relayed IP Address to exchange data between peers that are behind NATs.
To create a new Relayed IP Address on a TURN server, the client must first call the method Allocate, this method sends a Request to the TURN server to create a new Relayed IP Address, if the TURN server can create a new Relayed IP Address, the client will receive a successful response. The client will be able to communicate with other peers during the time defined in the Allocation's lifetime.
TsgcTURNClient oTURN = new TsgcTURNClient();
oTURN.Host = "turn.sgcwebsockets.com";
oTURN.Port = 3478;
oTURN.Allocate();
private void OnTURNAllocate(Component Sender, TsgcSocketConnection aSocket, TsgcSTUN_Message aMessage,
const TsgcTURN_ResponseAllocation aAllocation)
{
DoLog("Relayed IP: " + aAllocation.RelayedIP + ". Relayed Port: " +
aAllocation.RelayedPort.ToString());
}
private void OnSTUNResponseError(Component Sender, TsgcSTUN_Message aMessage,
TsgcSTUN_ResponseError aError)
{
DoLog("Error: " + aError.Code.ToString() + " " + aError.Reason);
}
The lifetime can be updated to avoid expiration using the method Refresh. The Lifetime is the number of seconds to expire. If the value is zero the Allocation will be deleted.
oTURN.Refresh(600);