# Class WebSock

WebSocket 封装

1. 连接/断开相关接口
2. 网络异常回调
3. 数据发送与接收

#### Hierarchy

- WebSock

#### Implements

- ISocket

- Defined in assets/libs/network/WebSock.ts:18

#####
Index

### Constructors

constructor

### Properties

_ws
onClosed
onConnected
onError
onMessage

### Methods

close
connect
send

## Constructors

### constructor

- new WebSock(): WebSock

- #### Returns WebSock

## Properties

### `Private` _ws

_ws: null | WebSocket = null

- Defined in assets/libs/network/WebSock.ts:19

### onClosed

onClosed: null | ((this: WebSocket, ev: CloseEvent) => any) = null

网络断开事件

Implementation of ISocket.onClosed

- Defined in assets/libs/network/WebSock.ts:28

### onConnected

onConnected: null | ((this: WebSocket, ev: Event) => any) = null

网络连接成功事件

Implementation of ISocket.onConnected

- Defined in assets/libs/network/WebSock.ts:22

### onError

onError: null | ((this: WebSocket, ev: Event) => any) = null

网络错误事件

Implementation of ISocket.onError

- Defined in assets/libs/network/WebSock.ts:26

### onMessage

onMessage: null | MessageFunc = null

接受到网络数据事件

Implementation of ISocket.onMessage

- Defined in assets/libs/network/WebSock.ts:24

## Methods

### close

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

- 网络断开

  #### Parameters

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

    关闭码

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

    关闭原因

  #### Returns void

  Implementation of ISocket.close

  - Defined in assets/libs/network/WebSock.ts:79

### connect

- connect(options: any): boolean

- 请求连接

  #### Parameters

  - ##### options: any

  #### Returns boolean

  Implementation of ISocket.connect

  - Defined in assets/libs/network/WebSock.ts:31

### send

- send(buffer: NetData ): number

- 发送数据

  #### Parameters

  - ##### buffer: NetData

    网络数据

  #### Returns number

  Implementation of ISocket.send

  - Defined in assets/libs/network/WebSock.ts:66

Generated using TypeDoc