# Class: HttpServer

## vertx-js/http_server~ HttpServer

#### new HttpServer()

An HTTP and WebSockets server.

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

### Methods

#### actualPort() → {number}

The actual port the server is listening on. This is useful if you bound the server specifying 0 as port number signifying an ephemeral port

Source:
  - vertx-js/http_server.js, line 241

##### Returns:

the actual port the server is listening on.

Type
  number

#### close(completionHandler)

Like HttpServer#close but supplying a handler that will be called when the server is actually closed (or has failed).

##### Parameters:

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

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

#### connectionHandler(handler) → {HttpServer}

Set a connection handler for the server.

##### Parameters:

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

Source:
  - vertx-js/http_server.js, line 97

##### Returns:

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

Type
  HttpServer

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

Set an exception handler called for socket errors happening before the HTTP connection is established, e.g during the TLS handshake.

##### Parameters:

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

Source:
  - vertx-js/http_server.js, line 115

##### Returns:

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

Type
  HttpServer

#### isMetricsEnabled() → {boolean}

Whether the metrics are enabled for this measured object

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

##### Returns:

true if the metrics are enabled

Type
  boolean

#### listen(port, host, listenHandler) → {HttpServer}

Like HttpServer#listen but supplying a handler that will be called when the server is actually listening (or has failed).

##### Parameters:

Name | Type | Description
--- | --- | ---
`port` | number | the port to listen on
`host` | string | the host to listen on
`listenHandler` | function | the listen handler

Source:
  - vertx-js/http_server.js, line 171

##### Returns:

Type
  HttpServer

#### requestHandler(handler) → {HttpServer}

Set the request handler for the server to `requestHandler`. As HTTP requests are received by the server, instances of HttpServerRequest will be created and passed to this handler.

##### Parameters:

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

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

##### Returns:

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

Type
  HttpServer

#### requestStream() → {ReadStream}

Return the request stream for the server. As HTTP requests are received by the server, instances of HttpServerRequest will be created and passed to the stream .

Source:
  - vertx-js/http_server.js, line 62

##### Returns:

the request stream

Type
  ReadStream

#### websocketHandler(handler) → {HttpServer}

Set the websocket handler for the server to `wsHandler`. If a websocket connect handshake is successful a new ServerWebSocket instance will be created and passed to the handler.

##### Parameters:

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

Source:
  - vertx-js/http_server.js, line 151

##### Returns:

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

Type
  HttpServer

#### websocketStream() → {ReadStream}

Return the websocket stream for the server. If a websocket connect handshake is successful a new ServerWebSocket instance will be created and passed to the stream .

Source:
  - vertx-js/http_server.js, line 133

##### Returns:

the websocket stream

Type
  ReadStream