proxy_client
简介
做为客户端接入proxy server
- 一般是玩家客户端(大部分情况下为非gs实现)才需要接入proxy server;
这个pkg主要是client gs使用,用来实现一些测试功能以及演示如何接入proxy server;
组件接口
CommonConnection.gs
公共服务器代理连接对象(用于pkg.request_client)
| 函数原型 | 函数作用 |
|---|---|
| void FProxyConnection.process_command(mixed payload) | 虚函数 - 公共服务器消息的处理函数 |
FProxyConnection.gs
代理连接对象的基础组件,所有的代理连接对象都应该继承本组件
| 函数原型 | 函数作用 |
|---|---|
| object get_proxy_client_ob() | 获取本连接关联的代理客户端对象 |
| string get_name() | 获取本连接名称 |
| void on_message(string msg, function func) | 设置消息处理函数 |
| object bind_dispatcher(mixed co) | 绑定消息处理协程对象 |
| bool is_connected() | 连接是否已建立 |
| void send(string cmd, ...) | 虚函数 - 向目标服务器发送消息 |
| mixed send_request(string cmd, ...) | 虚函数 - 向目标服务器发送消息并等待消息处理结果 |
ProxyClient.gs
接入proxy server的客户端连接对象
ProxyClient对象在创建时可以指定对象的所有者owner;owner对象将处理ProxyClient对象收到的消息(调用owner的perform_recv_in_co方法);
当owner对象未指定时(为nil),ProxyClient对象收到的消息将直接丢弃;
| 函数原型 | 函数作用 |
|---|---|
| void add_connection(string name, object connection) | 添加一个代理连接 |
| object remove_connection(string name) | 移除一个代理连接 |
| object get_connection(string name) | 根据连接名称获取代理连接对 象 |
| void set_connection_factory(string type, function func) | 设置指定类型的代理连接对象的创建函数 |
| object new_connection(ProxyConnectionProperties properties) | 通过指定参数新建一个代理连接对象 |
| void close_connection(string name) | 关闭指定名称的代理连接 |
| bool connect(string host, int port, map para = , bool using_websocket = false) | 连接代理服务器 |
| void send(string cmd, ...) | 向代理服务器发送消息 |
| mixed send_request(string cmd, map args, int timeout = 30) | 向代理服务器发送消息并等待消息处理结果 |
| void disconnect() | 主动断开和代理服务器的连接 |
| void on_message(string msg, function func) | 响应指定名称的网络消息 |
| void invoke_message(string msg, ...) | 执行消息处理函数 |
proxy_client.gs
| 函数原型 | 函数作用 |
|---|---|
| object create_client(map para = ) | 创建一个到proxy server的客户端连接 |
类
ProxyConnectionProperties
代理连接的属性表
成员变量
| 变量名 | 类型 | 初始值 | 须初始化 | 描述 |
|---|---|---|---|---|
| name | string | nil | 可选 | 代理连接名称(ProxyClient实例下唯一) |
| type | string | nil | 可选 | 连接类型(代理服务器允许的连接类型) |
| host | string | nil | 可选 | 目标服务器地址 |
| port | int | 0 | 可选 | 目标服务器端口 |
| connect_para | map | nil | 可选 | 目标服务器的额外连接参数 |
成员方法
| 函数原型 | 函数作用 |
|---|---|
| map get_properties() | 获取代理连接的属性 |