# Class: NetSocket

## vertx-js/net_socket~ NetSocket

#### new NetSocket()

Represents a socket-like interface to a TCP connection on either the client or the server side.

Source:
  - vertx-js/net_socket.js, line 34

### Methods

#### close()

Close the NetSocket

Source:
  - vertx-js/net_socket.js, line 303

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

Set a handler that will be called when the NetSocket is closed

##### Parameters:

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

Source:
  - vertx-js/net_socket.js, line 317

##### Returns:

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

Type
  NetSocket

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

##### Parameters:

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

Source:
  - vertx-js/net_socket.js, line 186

##### Returns:

Type
  NetSocket

#### end(t)

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

##### Parameters:

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

Source:
  - vertx-js/net_socket.js, line 47

#### endHandler(endHandler) → {NetSocket}

##### Parameters:

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

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

##### Returns:

Type
  NetSocket

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

##### Parameters:

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

Source:
  - vertx-js/net_socket.js, line 76

##### Returns:

Type
  NetSocket

#### handler(handler) → {NetSocket}

##### Parameters:

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

Source:
  - vertx-js/net_socket.js, line 92

##### Returns:

Type
  NetSocket

#### isSsl() → {boolean}

Source:
  - vertx-js/net_socket.js, line 346

##### Returns:

true if this NetSocket is encrypted via SSL/TLS.

Type
  boolean

#### localAddress() → {SocketAddress}

Source:
  - vertx-js/net_socket.js, line 287

##### Returns:

the local address for this socket

Type
  SocketAddress

#### pause() → {NetSocket}

Source:
  - vertx-js/net_socket.js, line 108

##### Returns:

Type
  NetSocket

#### remoteAddress() → {SocketAddress}

Source:
  - vertx-js/net_socket.js, line 271

##### Returns:

the remote address for this socket

Type
  SocketAddress

#### resume() → {NetSocket}

Source:
  - vertx-js/net_socket.js, line 122

##### Returns:

Type
  NetSocket

#### sendFile(filename, offset, length, resultHandler) → {NetSocket}

Same as NetSocket#sendFile but also takes a handler that will be called when the send has completed or a failure has occurred

##### Parameters:

Name | Type | Description
--- | --- | ---
`filename` | string | file name of the file to send
`offset` | number | offset
`length` | number | length
`resultHandler` | function | handler

Source:
  - vertx-js/net_socket.js, line 224

##### Returns:

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

Type
  NetSocket

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

##### Parameters:

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

Source:
  - vertx-js/net_socket.js, line 172

##### Returns:

Type
  NetSocket

#### upgradeToSsl(handler) → {NetSocket}

Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler will be notified when it's upgraded

Source:
  - vertx-js/net_socket.js, line 332

##### Returns:

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

Type
  NetSocket

#### write(str, enc) → {NetSocket}

Write a String to the connection, encoded using the encoding `enc`.

##### Parameters:

Name | Type | Description
--- | --- | ---
`str` | string | the string to write
`enc` | string | the encoding to use

Source:
  - vertx-js/net_socket.js, line 152

##### Returns:

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

Type
  NetSocket

#### writeHandlerID() → {string}

When a `NetSocket` is created it automatically registers an event handler with the event bus, the ID of that handler is given by `writeHandlerID`.

Given this ID, a different event loop can send a buffer 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 connections which are owned by different event loops.

Source:
  - vertx-js/net_socket.js, line 206

##### Returns:

the write handler ID

Type
  string

#### writeQueueFull() → {boolean}

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

Source:
  - vertx-js/net_socket.js, line 63

##### Returns:

true if write queue is full

Type
  boolean