TURN | TsgcTURNServer

TsgcTURNServer is the server that implements the TURN protocol and allows to process requests from TURN clients. The component inherits from TsgcSTUNServer, so all methods and properties are available on TsgcTURNServer.

 

TURN Server supports Long-Term Authentication, Allocation, Permissions, Channel Data and more.

 

Basic usage

Usually TURN servers runs on UDP port 3478 and require Long-Term credentials, so in order to configure a TURN server, set the listening port (by default 3478) and start the server.

 

Configure the server

 

Set the property Active = True to start the STUN server.

 


oTURN := TsgcTURNServer.Create(nil);
oTURN.Port := 3478;
oTURN.TURNOptions.Authentication.Enabled := True;
oTURN.TURNOptions.Authentication.LongTermCredentials.Enabled := True;
oTURN.TURNOptions.Authentication.LongTermCredentials.Realm := 'esegece.com';
oTURN.Active := True;
procedure OnSTUNRequestAuthorization(Sender: TObject; const aRequest: TsgcSTUN_Message; 
  const aUsername, aRealm: string; var Password: string);
begin
  if (aUsername = 'user') and (aRealm = 'esegece.com') then
    Password := 'password';
end;

Most common uses

 

 

Properties

    Active: set the property to True to Start the TURN server and set to False to Stop the Server.

 

    Host: it's the IP Address or DNS name of TURN server.

 

    Port: it's the listening port of TURN server, by default 3478.

 

    IPVersion: it's the Family Address, by default IPv4.

 

    STUNOptions: here are defined the specific options for STUN Requests

 

Fingerprint: if enabled, the message includes a fingerprint that aids to identify STUN messages from packets of other protocols when the two are multiplexed on the same transport address.

 

Software: if enabled, sends an attribute with the name of the software being used by the server.

 

Authentication: here you can configure if the server requires Authentication requests to send binding responses.

 

 

BindingAttributes: when the server sends a successful response after a binding request, here you can customize which attributes will be sent to the client.

 

 

 

 

    TURNOptions: here are defined the specific options for TURN Requests

 

Fingerprint: if enabled, the message includes a fingerprint that aids to identify TURN messages from packets of other protocols when the two are multiplexed on the same transport address.

 

Software: if enabled, sends an attribute with the name of the software being used by the server.

 

Allocation: when a new allocation is created, the server takes from this property the default values.

 

 

Authentication: usually TURN servers require Long-Term Credentials authentication.

 

 

 

    LogFile: if enabled save stun messages to a specified log file, useful for debugging.

 

Enabled: if enabled every time a message is received and sent by server it will be saved on a file.

 

FileName: full path to the filename.

 

    NotifyEvents: defines which mode to notify the events.

 

neAsynchronous: this is the default mode, notify threaded events on asynchronous mode, adds events to a queue that are synchronized with the main thread asynchronously.

 

neSynchronous: if this mode is selected, notify threaded events on synchronous mode, needs to synchronize with the main thread to notify these events.

 

neNoSync: there is no synchronization with the main thread, if you need to access to controls that are not thread-safe, you need to implement your own synchronization methods.

 

Events

The TURN server inherits from STUN Server the events: OnSTUNRequestAuthorization, OnSTUNRequestSuccess, OnSTUNRequestError and OnSTUNException.

 

Additionally, includes the following events to handle all TURN messages.

 

    OnTURNBeforeAllocate

 

The event is called before create a new Allocation. It provides the IP Address and Port used to Relay Data, you can reject if don't want to accept the Allocation.

 

    OnTURNCreateAllocation

 

The event is called after creating successfully an Allocation.

 

    OnTURNDeleteAllocation

 

The event is called after remove an already created Allocation.

 

    OnTURNMessageDiscarded

 

The event is called when a message received by server is discarded.

 

    OnTURNChannelDataDiscarded

 

The event is called when a Channel Data message is discarded.

 

    OnTURNBeforeRelayIndication

 

Event fired when the server receives an indication that must be relayed to other peer, you can use this method to intercept the bytes sent to the peer (to capture audio/video for example).

 

    OnTURNBeforeRelayChannelData

 

Event fired when the server receives a channel data message that must be relayed to other peer, you can use this method to intercept the bytes sent to the peer (to capture audio/video for example).