From sgcWebSockets 2022.6 a new component is included in the library, the ICE client which implements the RFC8445. ICE is one of the protocols used on WebRTC (with STUN, TURN, WebSockets... which are already supported). Interactive Connectivity Establishment (ICE) is a technique used in computer networking to find ways for two computers to talk to each other as directly as possible in peer-to-peer networking. This is most commonly used for interactive media such as Voice over Internet Protocol (VoIP), peer-to-peer communications, video, and instant messaging. In such applications, communicating through a central server would be slow and expensive, but direct communication between client applications on the Internet is very tricky due to network address translators (NATs), firewalls, and other network barriers.
ICE starts gathering candidates, usually will obtain local IP Addresses, reflexive address using STUN protocol and relayed address using TURN protocol.
To start the gathering call the method GatherCandidates, this will start an internal timer where first will obtain the local IP addresses, then will connect to the STUN server to obtain the reflexive IP Address and finally will connect to TURN server to obtain the relayed IP Address.
Every time a new candidate is obtained, the event OnICECandidate will be called asynchronously, if there is any error while gathering the candidates, the event OnICECandidateError will be triggered.
oICE := TsgcICEClient.Create(nil); oTURN := TsgcTURNClient.Create(nil); oTURN.Host := 'www.esegece.com'; oTURN.Port := 3478; oTURN.TURNOptions.Authentication.Credentials := stauLongTermCredential; oTURN.TURNOptions.Authentication.Username := 'sgc'; oTURN.TURNOptions.Authentication.Password := 'secret'; oICE.GatherCandidates(); procedure OnICECandidate(Sender: TObject; const aCandidate: TsgcICE_Candidate); begin DoLog('[#Candidate] ' + aCandidate.AsString); end;
Once the Candidates have been obtained (local and remote) and the SDP descriptions have been set, the ICE caller client can start to process all the pair candidates to find those that can exchange data. To start this process, call the method ProcessCandidates.
The method ProcessCandidates evaluate all pair candidates sending a STUN binding packet, if the STUN binding packet is received as an answer from the other peer, means the connection is possible between those 2 peers, so the pair is nominated.
When the pairing is successful, the event OnICECandidatePairNominated is triggered asynchronously. If the pairing has an error or cannot connect after a timeout, the event OnICECandidatePairFailed is triggered.
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.