STUN | TsgcSTUNServer

TsgcSTUNServer is the server that implements the STUN protocol and allows to process binding requests from STUN clients.

 

The STUN server can be configured with or without Authentication, can verify Fingerprint Attribute, send an alternate server and more.

Basic usage

Usually stun servers runs on UDP port 3478 and don't require authentication, so in order to configure a STUN 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.

 


oSTUN := TsgcSTUNServer.Create(nil);
oSTUN.Port := 3478;
oSTUN.Active := True;

 

Most common uses

 

 

Properties

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

 

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

 

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

 

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

 

    STUNOptions: here are defined the specific STUN options of server component

 

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.

 

 

    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

    OnSTUNRequestAuthorization

 

This event is called when a binding request is received and requires authentication.

 

    OnSTUNRequestSuccess

 

When the server processes successfully a request binding, it sends a message with the binding properties (IP Address, Port and family) and other attributes, this event is called before the message is sent to client.

 

    OnSTUNRequestError

 

When there is any error in the response sent by server, , this event is called before the message is sent to client.

 

    OnSTUNException

 

This event is called when there is any exception processing the STUN protocol messages.