长期凭据机制依赖于一种长期凭据, 以用户名和密码的形式在客户端 和服务器之间共享。该凭据被认为是长期的,因为它假定为用户配置,并在用户不再是系统订阅者或凭据被更改之前一直有效。
您可以使用以下代码在 sgcWebSockets STUN 客户端中配置长期凭据。
oSTUN := TsgcSTUNClient.Create(nil);
oSTUN.Host := 'stun.sgcwebsockets.com';
oSTUN.Port := 3478;
oSTUN.STUNOptions.Authentication.Credentials := stauLongTermCredential;
oSTUN.STUNOptions.Authentication.Username := 'user_name';
oSTUN.STUNOptions.Authentication.Password := 'secret';
oSTUN.SendRequest;
如果服务器需要长期凭证而客户端发送的凭证有误,客户端将在 OnSTUNResponseError 事件中收到 401 Unauthorized 错误响应。