一、Connecting连接
sgs客户端第一件要做的事情就是与服务器建立连接。 连接的步骤有以下:
1、 创建一个SimpleClient实例
你需要做的第一件事情就是实例化一个SimpleClient.SimpleClient 的构造器需要一个参数:一个 SimpleClientListener ,用于调用通信的事件。在一般基础的客户端程序中,这就相当于一个主类,它的代码的大体看起来如下所示:
public class Client extends EventDispatcher implements SimpleClientListener
{
//....
{
//....
client=new SimpleClient(this);
}
2、Create the login properties.创建一个登陆的属性。
SimpleClient 登陆的方法需要一个参数即可,一个( 属性 ) 对象。在AS3中这个对象由Object构造,这个 SimpleClient的实例设置了两个属性:主机和端口。下面的例子演示了如何设置这些属性:
var connectProps:Object=new Object();
connectProps[ClientConnector.HOST]=host;
connectProps[ClientConnector.PORT]=port;
connectProps[ClientConnector.HOST]=host;
connectProps[ClientConnector.PORT]=port;
3、Call the login method.调用登陆方法
this.client.login(connectProps);
4、发送验证消息
为了响应你的登陆请求, API 将调用用 getPasswordAuthentication ( 获取密码验证 ) 来响应你的SimpleClientListener ( 简单客户端的监听器 ) 的用户名和密码的登陆请求。 “ Password ” 在这里是一种常见的验证信息的形式,该验证服务返回给 API( 即客户端 API) 一个二进制的数组 。
得到什么信息,和你服务器安装的验证程序有关。默认的验证信息是返回密码的完整信息,允许任何人登陆。 PDS 环境也通过验证服务器返回一个 hash 字符串。可以复写其他的验 证者来支持用户特定的验证服务。
private var _user:PasswordAuthentication;
public function get passwordAuthentication():PasswordAuthentication
{
return this._user;
}
public function set passwordAuthentication(pauth:PasswordAuthentication):void
{
this._user=pauth;
}
public function get passwordAuthentication():PasswordAuthentication
{
return this._user;
}
public function set passwordAuthentication(pauth:PasswordAuthentication):void
{
this._user=pauth;
}