From fc524ff701daf17cbbccffe5ed539286af5e2326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=9D=E7=88=B7?= Date: Tue, 8 Oct 2019 22:16:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E7=BB=9C=E7=AE=A1=E7=90=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Script/network/NetInterface.ts | 6 +++++ assets/Script/network/NetManager.ts | 32 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) 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