TsgcSTUNClient

Componente TsgcSTUNClient.

Introduzione

TsgcSTUNClient è il client che implementa il protocollo STUN e consente di inviare richieste di binding ai server STUN.

 

Il componente consente di utilizzare UDP e TCP come trasporto. Quando si utilizza UDP come trasporto, implementa un meccanismo di ritrasmissione per reinviare le richieste se la risposta non è arrivata entro un breve intervallo di tempo.

 

Utilizzo di base

Di solito i server STUN sono in esecuzione sulla porta UDP 3478 e non richiedono autenticazione; pertanto, per inviare una richiesta di binding STUN, compilare le proprietà del server per consentire al client di sapere dove connettersi e gestire gli eventi in cui il componente riceverà la risposta dal server.

 

Configurare il server

 

Chiamare il metodo SendRequest, per inviare una richiesta di binding al server STUN.

 

Gestire gli eventi

 


    oSTUN := TsgcSTUNClient.Create(nil);
    oSTUN.Host := 'stun.sgcwebsockets.com';
    oSTUN.Port := 3478;
    oSTUN.SendRequest;

    procedure OnSTUNResponseSuccess(Sender: TObject; const aSocket: TsgcSocketConnection; 
      const aMessage: TsgcSTUN_Message; const aBinding: TsgcSTUN_ResponseBinding);
    begin
      DoLog('Remote IP: ' + aBinding.RemoteIP + '. Remote Port: ' + IntToStr(aBinding.RemotePort));
    end;

    procedure OnSTUNResponseError(Sender: TObject; const aSocket: TsgcSocketConnection; 
      const aMessage: TsgcSTUN_Message; const aError: TsgcSTUN_ResponseError);
    begin
      DoLog('Error: ' + IntToStr(aError.Code) + ' ' + aError.Reason);
    end;

 

Riferimento

Guide