diff --git a/assets/Script/network/NetInterface.ts b/assets/Script/network/NetInterface.ts index 78f7a50..e1c525c 100644 --- a/assets/Script/network/NetInterface.ts +++ b/assets/Script/network/NetInterface.ts @@ -1,4 +1,10 @@ +/* +* 网络相关接口定义 +* +* 2019-10-8 by 宝爷 +*/ + export type NetData = (string | ArrayBufferLike | Blob | ArrayBufferView); export type NetCallFunc = (mainCmd: number, subCmd: number, data: any) => void; diff --git a/assets/Script/network/NetManager.ts b/assets/Script/network/NetManager.ts index 3cd55d0..cf7ac01 100644 --- a/assets/Script/network/NetManager.ts +++ b/assets/Script/network/NetManager.ts @@ -1,9 +1,41 @@ +import { NetNode } from "./NetNode"; /* * 网络节点管理类 * +* 2019-10-8 by 宝爷 */ export class NetManager { + protected _channels: { [key:number]: NetNode } = {} + // 添加Node,返回ChannelID + public setNetNode(channelId: number, newNode: NetNode) { + this._channels[channelId] = newNode; + } + + // 移除Node + public removeNetNode(channelId: number) { + delete this._channels[channelId]; + } + + // 调用Node连接 + public connect(options: any, channelId: number = 0):boolean { + if (this._channels[channelId]) { + // return this._channels[channelId].connect(options); + } + return false; + } + + // 调用Node发送 + public send() { + + } + + // 调用Node关闭 + public close(code?: number, reason?: string, channelId: number = 0) { + if (this._channels[channelId]) { + return this._channels[channelId].closeSocket(code, reason); + } + } } \ No newline at end of file