Protected
_channelsStatic
Private
_instance网络节点连接服务器
var options = {
url: 'ws://127.0.0.1:3000',
autoReconnect: 0 // -1 永久重连,0不自动重连,其他正整数为自动重试次数
}
NetManager.getInstance().connect(options, NetChannelType.Game);
连接参数
通道编号
发起请求,并在在结果返回时调用指定好的回调函数
let protocol: IRequestProtocol = {
action: action,
method: method,
data: JSON.stringify(data),
isCompress: this.isCompress,
channelid: netConfig.channelid
}
return this.request(protocol, rspObject, showTips, force);
请求协议
回调对象
是否触发请求提示
是否强制发送
通道编号
同request功能一致,但在request之前会先判断队列中是否已有rspCmd,如有重复的则直接返回
let protocol: IRequestProtocol = {
action: action,
method: method,
data: JSON.stringify(data),
isCompress: this.isCompress,
channelid: netConfig.channelid
}
return this.request(protocol, rspObject, showTips, force);
请求协议
回调对象
是否触发请求提示
是否强制发送
通道编号
添加网络节点
// 游戏服务器心跳协议
class GameProtocol extends NetProtocolPako {
// 自定义心跳协议
getHearbeat(): NetData {
return '{"action":"LoginAction","method":"heart","data":"null","callback":"LoginAction_heart"}';
}
}
var net = new NetNodeGame();
var ws = new WebSock(); // WebSocket 网络连接对象
var gp = new GameProtocol(); // 网络通讯协议对象
var gt = new NetGameTips() // 网络提示对象
net.init(ws, gp, gt);
NetManager.getInstance().setNetNode(net, NetChannelType.Game);
网络节点
通道编号
Static
get网络管理单例对象
Generated using TypeDoc
节点网络断开
Example