io.vertx.core.http

## Interface HttpServer

- All Superinterfaces:
    Measured

      public interface HttpServer
      extends Measured

  An HTTP and WebSockets server.

  You receive HTTP requests by providing a `requestHandler(io.vertx.core.Handler<io.vertx.core.http.HttpServerRequest>)`. As requests arrive on the server the handler will be called with the requests.

  You receive WebSockets by providing a `websocketHandler(io.vertx.core.Handler<io.vertx.core.http.ServerWebSocket>)`. As WebSocket connections arrive on the server, the WebSocket is passed to the handler.

  Author:
    Tim Fox

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `actualPort()` The actual port the server is listening on.
    `void` | `close()` Close the server.
    `void` | `close(Handler<AsyncResult<Void>> completionHandler)` Like `close()` but supplying a handler that will be called when the server is actually closed (or has failed).
    `HttpServer` | `connectionHandler(Handler<HttpConnection> handler)` Set a connection handler for the server.
    `HttpServer` | `listen()` Tell the server to start listening.
    `HttpServer` | `listen(Handler<AsyncResult<HttpServer>> listenHandler)` Like `listen()` but supplying a handler that will be called when the server is actually listening (or has failed).
    `HttpServer` | `listen(int port)` Like `listen(int, String)` but the server will listen on host "0.0.0.0" and port specified here ignoring any value in the `HttpServerOptions` that was used when creating the server.
    `HttpServer` | `listen(int port, Handler<AsyncResult<HttpServer>> listenHandler)` Like `listen(int)` but supplying a handler that will be called when the server is actually listening (or has failed).
    `HttpServer` | `listen(int port, String host)` Tell the server to start listening.
    `HttpServer` | `listen(int port, String host, Handler<AsyncResult<HttpServer>> listenHandler)` Like `listen(int, String)` but supplying a handler that will be called when the server is actually listening (or has failed).
    `Handler<HttpServerRequest>` | `requestHandler()`
    `HttpServer` | `requestHandler(Handler<HttpServerRequest> handler)` Set the request handler for the server to `requestHandler`.
    `ReadStream<HttpServerRequest>` | `requestStream()` Return the request stream for the server.
    `Handler<ServerWebSocket>` | `websocketHandler()`
    `HttpServer` | `websocketHandler(Handler<ServerWebSocket> handler)` Set the websocket handler for the server to `wsHandler`.
    `ReadStream<ServerWebSocket>` | `websocketStream()` Return the websocket stream for the server.

    - ### Methods inherited from interface io.vertx.core.metrics.Measured

      `isMetricsEnabled`

- - ### Method Detail

    - #### requestStream

          ReadStream<HttpServerRequest> requestStream()

      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 `ReadStream.handler(io.vertx.core.Handler)`.
      Returns:
        the request stream

    - #### requestHandler

          HttpServer requestHandler(Handler<HttpServerRequest> handler)

      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.
      Returns:
        a reference to this, so the API can be used fluently

    - #### requestHandler

          Handler<HttpServerRequest> requestHandler()

      Returns:
        the request handler

    - #### connectionHandler

          HttpServer connectionHandler(Handler<HttpConnection> handler)

      Set a connection handler for the server.
      Returns:
        a reference to this, so the API can be used fluently

    - #### websocketStream

          ReadStream<ServerWebSocket> websocketStream()

      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 `ReadStream.handler(io.vertx.core.Handler)`.
      Returns:
        the websocket stream

    - #### websocketHandler

          HttpServer websocketHandler(Handler<ServerWebSocket> handler)

      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.
      Returns:
        a reference to this, so the API can be used fluently

    - #### websocketHandler

          Handler<ServerWebSocket> websocketHandler()

      Returns:
        the websocketHandler

    - #### listen

          HttpServer listen()

      Tell the server to start listening. The server will listen on the port and host specified in the `HttpServerOptions` that was used when creating the server.

      The listen happens asynchronously and the server may not be listening until some time after the call has returned.

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

    - #### listen

          HttpServer listen(int port,
                            String host)

      Tell the server to start listening. The server will listen on the port and host specified here, ignoring any value set in the `HttpServerOptions` that was used when creating the server.

      The listen happens asynchronously and the server may not be listening until some time after the call has returned.

      Parameters:
        `port` - the port to listen on
        `host` - the host to listen on
      Returns:
        a reference to this, so the API can be used fluently

    - #### listen

          HttpServer listen(int port,
                            String host,
                            Handler<AsyncResult<HttpServer>> listenHandler)

      Like `listen(int, String)` but supplying a handler that will be called when the server is actually listening (or has failed).
      Parameters:
        `port` - the port to listen on
        `host` - the host to listen on
        `listenHandler` - the listen handler

    - #### listen

          HttpServer listen(int port)

      Like `listen(int, String)` but the server will listen on host "0.0.0.0" and port specified here ignoring any value in the `HttpServerOptions` that was used when creating the server.
      Parameters:
        `port` - the port to listen on
      Returns:
        a reference to this, so the API can be used fluently

    - #### listen

          HttpServer listen(int port,
                            Handler<AsyncResult<HttpServer>> listenHandler)

      Like `listen(int)` but supplying a handler that will be called when the server is actually listening (or has failed).
      Parameters:
        `port` - the port to listen on
        `listenHandler` - the listen handler

    - #### listen

          HttpServer listen(Handler<AsyncResult<HttpServer>> listenHandler)

      Like `listen()` but supplying a handler that will be called when the server is actually listening (or has failed).
      Parameters:
        `listenHandler` - the listen handler

    - #### close

          void close()

      Close the server. Any open HTTP connections will be closed.

      The close happens asynchronously and the server may not be closed until some time after the call has returned.

    - #### close

          void close(Handler<AsyncResult<Void>> completionHandler)

      Like `close()` but supplying a handler that will be called when the server is actually closed (or has failed).
      Parameters:
        `completionHandler` - the handler

    - #### actualPort

          int actualPort()

      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
      Returns:
        the actual port the server is listening on.

Copyright © 2017. All rights reserved.