# Class NetNode

网络节点

#### Hierarchy

- NetNode

- Defined in assets/libs/network/NetNode.ts:44

#####
Index

### Constructors

constructor

### Properties

_autoReconnect
_callbackExecuter
_connectOptions
_connectedCallback
_disconnectCallback
_heartTime
_isSocketInit
_isSocketOpen
_keepAliveTimer
_listener
_networkTips
_protocolHelper
_receiveMsgTimer
_receiveTime
_reconnectTimer
_reconnetTimeOut
_requests
_socket
_state

### Methods

addResponeHandler
base_request
cleanListeners
clearTimer
close
closeSocket
connect
getNetListenersIndex
init
initSocket
isAutoReconnect
onChecked
onClosed
onConnected
onError
onMessage
rejectReconnect
removeResponeHandler
request
requestUnique
resetHearbeatTimer
resetReceiveMsgTimer
send
setResponeHandler
updateNetTips

## Constructors

### constructor

- new NetNode(): NetNode

- #### Returns NetNode

## Properties

### `Protected` _autoReconnect

_autoReconnect: number = 0

- Defined in assets/libs/network/NetNode.ts:46

### `Protected` _callbackExecuter

_callbackExecuter: null | ExecuterFunc = null

- Defined in assets/libs/network/NetNode.ts:56

### `Protected` _connectOptions

_connectOptions: null | NetConnectOptions = null

- Defined in assets/libs/network/NetNode.ts:45

### `Protected` _connectedCallback

_connectedCallback: null | CheckFunc = null

- Defined in assets/libs/network/NetNode.ts:54

### `Protected` _disconnectCallback

_disconnectCallback: null | BoolFunc = null

- Defined in assets/libs/network/NetNode.ts:55

### `Protected` _heartTime

_heartTime: number = 10000

- Defined in assets/libs/network/NetNode.ts:61

### `Protected` _isSocketInit

_isSocketInit: boolean = false

- Defined in assets/libs/network/NetNode.ts:47

### `Protected` _isSocketOpen

_isSocketOpen: boolean = false

- Defined in assets/libs/network/NetNode.ts:48

### `Protected` _keepAliveTimer

_keepAliveTimer: any = null

- Defined in assets/libs/network/NetNode.ts:58

### `Protected` _listener

_listener: {
[key: string]: CallbackObject [] | null;
} = {}

#### Type declaration

- ##### [key: string]: CallbackObject [] | null

- Defined in assets/libs/network/NetNode.ts:65

### `Protected` _networkTips

_networkTips: null | INetworkTips = null

- Defined in assets/libs/network/NetNode.ts:52

### `Protected` _protocolHelper

_protocolHelper: null | IProtocolHelper = null

- Defined in assets/libs/network/NetNode.ts:53

### `Protected` _receiveMsgTimer

_receiveMsgTimer: any = null

- Defined in assets/libs/network/NetNode.ts:59

### `Protected` _receiveTime

_receiveTime: number = 6000000

- Defined in assets/libs/network/NetNode.ts:62

### `Protected` _reconnectTimer

_reconnectTimer: any = null

- Defined in assets/libs/network/NetNode.ts:60

### `Protected` _reconnetTimeOut

_reconnetTimeOut: number = 8000000

- Defined in assets/libs/network/NetNode.ts:63

### `Protected` _requests

_requests: RequestObject [] = ...

- Defined in assets/libs/network/NetNode.ts:64

### `Protected` _socket

_socket: null | ISocket = null

- Defined in assets/libs/network/NetNode.ts:50

### `Protected` _state

_state: NetNodeState = NetNodeState.Closed

- Defined in assets/libs/network/NetNode.ts:49

## Methods

### addResponeHandler

- addResponeHandler(cmd: string, callback: NetCallFunc, target?: any): boolean

- 可添加多个同类返回消息的监听

  ### Returns

  #### Parameters

  - ##### cmd: string

    命令字串

  - ##### callback: NetCallFunc

    回调方法

  - ##### `Optional` target: any

    目标对象

  #### Returns boolean

  - Defined in assets/libs/network/NetNode.ts:387

### `Private` base_request

- base_request(reqProtocol: IRequestProtocol, rspCmd: string, rspObject: CallbackObject, showTips?: boolean, force?: boolean): void

- #### Parameters

  - ##### reqProtocol: IRequestProtocol

  - ##### rspCmd: string

  - ##### rspObject: CallbackObject

  - ##### showTips: boolean = true

  - ##### force: boolean = false

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:345

### cleanListeners

- cleanListeners(cmd?: string): void

- 清除所有监听或指定命令的监听

  #### Parameters

  - ##### cmd: string = ""

    命令字串（默认不填为清除所有）

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:424

### `Protected` clearTimer

- clearTimer(): void

- #### Returns void

  - Defined in assets/libs/network/NetNode.ts:469

### close

- close(code?: number, reason?: string): void

- 断开网络

  #### Parameters

  - ##### `Optional` code: number

    关闭码

  - ##### `Optional` reason: string

    关闭原因

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:259

### closeSocket

- closeSocket(code?: number, reason?: string): void

- 只是关闭Socket套接字（仍然重用缓存与当前状态）

  #### Parameters

  - ##### `Optional` code: number

    关闭码

  - ##### `Optional` reason: string

    关闭原因

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:281

### connect

- connect(options: NetConnectOptions ): boolean

- 请求连接服务器

  #### Parameters

  - ##### options: NetConnectOptions

    连接参数

  #### Returns boolean

  - Defined in assets/libs/network/NetNode.ts:82

### `Protected` getNetListenersIndex

- getNetListenersIndex(cmd: string, rspObject: CallbackObject ): number

- #### Parameters

  - ##### cmd: string

  - ##### rspObject: CallbackObject

  #### Returns number

  - Defined in assets/libs/network/NetNode.ts:433

### init

- init(socket: ISocket, protocol: IProtocolHelper, networkTips?: null | INetworkTips, execFunc?: null | ExecuterFunc): void

- ******************** 网络相关处理 ********************

  #### Parameters

  - ##### socket: ISocket

  - ##### protocol: IProtocolHelper

  - ##### networkTips: null | INetworkTips = null

  - ##### execFunc: null | ExecuterFunc = null

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:68

### `Protected` initSocket

- initSocket(): void

- #### Returns void

  - Defined in assets/libs/network/NetNode.ts:102

### isAutoReconnect

- isAutoReconnect(): boolean

- 是否自动重连接

  #### Returns boolean

  - Defined in assets/libs/network/NetNode.ts:482

### `Protected` onChecked

- onChecked(): void

- 连接验证成功，进入工作状态

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:142

### `Protected` onClosed

- onClosed(event: any): void

- #### Parameters

  - ##### event: any

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:228

### `Protected` onConnected

- onConnected(event: any): void

- 网络连接成功

  #### Parameters

  - ##### event: any

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:127

### `Protected` onError

- onError(event: any): void

- #### Parameters

  - ##### event: any

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:224

### `Protected` onMessage

- onMessage(msg: any): void

- 接收到一个完整的消息包

  #### Parameters

  - ##### msg: any

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:170

### rejectReconnect

- rejectReconnect(): void

- 拒绝重新连接

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:487

### removeResponeHandler

- removeResponeHandler(cmd: string, callback: NetCallFunc, target?: any): void

- 删除一个监听中指定子回调

  #### Parameters

  - ##### cmd: string

    命令字串

  - ##### callback: NetCallFunc

    回调方法

  - ##### `Optional` target: any

    目标对象

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:411

### request

- request<T>(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips?: boolean, force?: boolean): void

- 发起请求，并进入缓存列表

  #### Type Parameters

  - #### T

  #### Parameters

  - ##### reqProtocol: IRequestProtocol

    请求协议

  - ##### rspObject: CallbackObject

    回调对象

  - ##### showTips: boolean = true

    是否触发请求提示

  - ##### force: boolean = false

    是否强制发送

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:319

### requestUnique

- requestUnique(reqProtocol: IRequestProtocol, rspObject: CallbackObject, showTips?: boolean, force?: boolean): boolean

- 唯一request，确保没有同一响应的请求（避免一个请求重复发送，netTips界面的屏蔽也是一个好的方法）

  #### Parameters

  - ##### reqProtocol: IRequestProtocol

    请求协议

  - ##### rspObject: CallbackObject

    回调对象

  - ##### showTips: boolean = true

    是否触发请求提示

  - ##### force: boolean = false

    是否强制发送

  #### Returns boolean

  - Defined in assets/libs/network/NetNode.ts:331

### `Protected` resetHearbeatTimer

- resetHearbeatTimer(): void

- #### Returns void

  - Defined in assets/libs/network/NetNode.ts:458

### `Protected` resetReceiveMsgTimer

- resetReceiveMsgTimer(): void

- ******************** 心跳、超时相关处理 ********************

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:447

### send

- send(buf: NetData, force?: boolean): number

- 发起请求，如果当前处于重连中，进入缓存列表等待重连完成后发送

  #### Parameters

  - ##### buf: NetData

    网络数据

  - ##### force: boolean = false

    是否强制发送

  #### Returns number

  - Defined in assets/libs/network/NetNode.ts:292

### setResponeHandler

- setResponeHandler(cmd: string, callback: NetCallFunc, target?: any): boolean

- 设置一个唯一的服务器推送监听

  #### Parameters

  - ##### cmd: string

    命令字串

  - ##### callback: NetCallFunc

    回调方法

  - ##### `Optional` target: any

    目标对象

  #### Returns boolean

  - Defined in assets/libs/network/NetNode.ts:371

### `Protected` updateNetTips

- updateNetTips(tipsType: NetTipsType, isShow: boolean): void

- #### Parameters

  - ##### tipsType: NetTipsType

  - ##### isShow: boolean

  #### Returns void

  - Defined in assets/libs/network/NetNode.ts:112

Generated using TypeDoc