# Class: WebSocket

## vertx-js/web_socket~ WebSocket

#### new WebSocket()

Represents a client-side WebSocket.

Source:
  - vertx-js/web_socket.js, line 33

### Methods

#### binaryHandlerID() → {string}

When a `Websocket` is created it automatically registers an event handler with the event bus - the ID of that handler is given by this method.

Given this ID, a different event loop can send a binary frame to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other WebSockets which are owned by different event loops.

Source:
  - vertx-js/web_socket.js, line 80

##### Returns:

the binary handler id

Type
  string

#### binaryMessageHandler(handler) → {WebSocketBase}

Set a binary message handler on the connection. This handler serves a similar purpose to WebSocket#handler except that if a message comes into the socket in multiple frames, the data from the frames will be aggregated into a single buffer before calling the handler (using WebSocketFrame#isFinal to find the boundaries).

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler

Source:
  - vertx-js/web_socket.js, line 193

##### Returns:

a reference to this, so the API can be used fluently

Type
  WebSocketBase

#### close()

Close the WebSocket.

Source:
  - vertx-js/web_socket.js, line 234

#### closeHandler(handler) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function |

Source:
  - vertx-js/web_socket.js, line 478

##### Returns:

Type
  WebSocket

#### drainHandler(handler) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function |

Source:
  - vertx-js/web_socket.js, line 394

##### Returns:

Type
  WebSocket

#### end(t)

Same as WebSocketBase#end but writes some data to the stream before ending.

##### Parameters:

Name | Type | Description
--- | --- | ---
`t` | Buffer |

Source:
  - vertx-js/web_socket.js, line 45

#### endHandler(endHandler) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`endHandler` | function |

Source:
  - vertx-js/web_socket.js, line 352

##### Returns:

Type
  WebSocket

#### exceptionHandler(handler) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function |

Source:
  - vertx-js/web_socket.js, line 292

##### Returns:

Type
  WebSocket

#### frameHandler(handler) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function |

Source:
  - vertx-js/web_socket.js, line 492

##### Returns:

Type
  WebSocket

#### handler(handler) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function |

Source:
  - vertx-js/web_socket.js, line 308

##### Returns:

Type
  WebSocket

#### isSsl() → {boolean}

Source:
  - vertx-js/web_socket.js, line 279

##### Returns:

true if this HttpConnection is encrypted via SSL/TLS.

Type
  boolean

#### localAddress() → {SocketAddress}

Source:
  - vertx-js/web_socket.js, line 263

##### Returns:

the local address for this socket

Type
  SocketAddress

#### pause() → {WebSocket}

Source:
  - vertx-js/web_socket.js, line 324

##### Returns:

Type
  WebSocket

#### pongHandler(handler) → {WebSocketBase}

Set a pong message handler on the connection. This handler will be invoked every time a pong message is received on the server, and can be used by both clients and servers since the RFC 6455 Sections 5.5.2 and 5.5.3 do not specify whether the client or server sends a ping.

Pong frames may be at most 125 bytes (octets).

There is no ping handler since pings should immediately be responded to with a pong with identical content

Pong frames may be received unsolicited.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler

Source:
  - vertx-js/web_socket.js, line 218

##### Returns:

a reference to this, so the API can be used fluently

Type
  WebSocketBase

#### remoteAddress() → {SocketAddress}

Source:
  - vertx-js/web_socket.js, line 247

##### Returns:

the remote address for this socket

Type
  SocketAddress

#### resume() → {WebSocket}

Source:
  - vertx-js/web_socket.js, line 338

##### Returns:

Type
  WebSocket

#### setWriteQueueMaxSize(maxSize) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`maxSize` | number |

Source:
  - vertx-js/web_socket.js, line 380

##### Returns:

Type
  WebSocket

#### subProtocol() → {string}

Returns the websocket sub protocol selected by the websocket handshake.

On the server, the value will be `null` when the handler receives the websocket callback as the handshake will not be completed yet.

Source:
  - vertx-js/web_socket.js, line 116

##### Returns:

Type
  string

#### textHandlerID() → {string}

When a `Websocket` is created it automatically registers an event handler with the eventbus, the ID of that handler is given by `textHandlerID`.

Given this ID, a different event loop can send a text frame to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other WebSockets which are owned by different event loops.

Source:
  - vertx-js/web_socket.js, line 99

##### Returns:

Type
  string

#### textMessageHandler(handler) → {WebSocketBase}

Set a text message handler on the connection. This handler will be called similar to the , but the buffer will be converted to a String first

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler

Source:
  - vertx-js/web_socket.js, line 174

##### Returns:

a reference to this, so the API can be used fluently

Type
  WebSocketBase

#### write(data) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Buffer |

Source:
  - vertx-js/web_socket.js, line 366

##### Returns:

Type
  WebSocket

#### writeBinaryMessage(data) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Buffer |

Source:
  - vertx-js/web_socket.js, line 450

##### Returns:

Type
  WebSocket

#### writeFinalBinaryFrame(data) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Buffer |

Source:
  - vertx-js/web_socket.js, line 436

##### Returns:

Type
  WebSocket

#### writeFinalTextFrame(text) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`text` | string |

Source:
  - vertx-js/web_socket.js, line 422

##### Returns:

Type
  WebSocket

#### writeFrame(frame) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`frame` | WebSocketFrame |

Source:
  - vertx-js/web_socket.js, line 408

##### Returns:

Type
  WebSocket

#### writePing(data) → {WebSocketBase}

Writes a ping to the connection. This will be written in a single frame. Ping frames may be at most 125 bytes (octets).

This method should not be used to write application data and should only be used for implementing a keep alive or to ensure the client is still responsive, see RFC 6455 Section 5.5.2.

There is no pingHandler because RFC 6455 section 5.5.2 clearly states that the only response to a ping is a pong with identical contents.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Buffer | the data to write, may be at most 125 bytes

Source:
  - vertx-js/web_socket.js, line 136

##### Returns:

a reference to this, so the API can be used fluently

Type
  WebSocketBase

#### writePong(data) → {WebSocketBase}

Writes a pong to the connection. This will be written in a single frame. Pong frames may be at most 125 bytes (octets).

This method should not be used to write application data and should only be used for implementing a keep alive or to ensure the client is still responsive, see RFC 6455 Section 5.5.2.

There is no need to manually write a Pong, as the server and client both handle responding to a ping with a pong automatically and this is exposed to users.RFC 6455 Section 5.5.3 states that pongs may be sent unsolicited in order to implement a one way heartbeat.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Buffer | the data to write, may be at most 125 bytes

Source:
  - vertx-js/web_socket.js, line 158

##### Returns:

a reference to this, so the API can be used fluently

Type
  WebSocketBase

#### writeQueueFull() → {boolean}

This will return `true` if there are more bytes in the write queue than the value set using WebSocket#setWriteQueueMaxSize

Source:
  - vertx-js/web_socket.js, line 61

##### Returns:

true if write queue is full

Type
  boolean

#### writeTextMessage(text) → {WebSocket}

##### Parameters:

Name | Type | Description
--- | --- | ---
`text` | string |

Source:
  - vertx-js/web_socket.js, line 464

##### Returns:

Type
  WebSocket