TsgcSTUNClient

TsgcSTUNClient-component.

Inleiding

TsgcSTUNClient is de client that implements the STUN protocol and allows you to send binding requests to STUN servers.

 

De component stelt u in staat UDP en TCP als transport te gebruiken. Bij gebruik van UDP als transport implementeert het een hertransmissiemechanisme om verzoeken opnieuw te versturen als het antwoord na korte tijd niet is ontvangen.

 

Basisgebruik

Usually STUN servers uitvoeren on UDP port 3478 and don't require authenticatie, so om send a STUN request binding, fill de server properties to allow de client to know where to connect and Handle the events where het component will receive de reactie from server.

 

De server configureren

 

Roep de methode SendRequest aan om een verzoek te verzenden dat gekoppeld is aan de STUN-server.

 

Handle the events

 


    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;

 

Referentie

Handleidingen