Package io.vertx.core.net

## Interface NetServer

- All Superinterfaces:
    `Measured`

      public interface NetServer
      extends Measured

  Represents a TCP server
  Author:
    Tim Fox

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `actualPort()` | The actual port the server is listening on.
    `default Future<Void>` | `close()` | Close the server.
    `Handler<NetSocket>` | `connectHandler()` |
    `NetServer` | `connectHandler​(Handler<NetSocket> handler)` | Supply a connect handler for this server.
    `NetServer` | `exceptionHandler​(Handler<Throwable> handler)` | Set an exception handler called for socket errors happening before the connection is passed to the `connectHandler(io.vertx.core.Handler<io.vertx.core.net.NetSocket>)`, e.g during the TLS handshake.
    `Future<NetServer>` | `listen()` | Start listening on the port and host as configured in the `NetServerOptions` used when creating the server.
    `default Future<NetServer>` | `listen​(int port)` | Start listening on the specified port and host "0.0.0.0", ignoring port and host configured in the `NetServerOptions` used when creating the server.
    `default Future<NetServer>` | `listen​(int port, String host)` | Start listening on the specified port and host, ignoring port and host configured in the `NetServerOptions` used when creating the server.
    `Future<NetServer>` | `listen​(SocketAddress localAddress)` | Start listening on the specified local address, ignoring port and host configured in the `NetServerOptions` used when creating the server.
    `default Future<Void>` | `shutdown()` | Shutdown with a 30 seconds timeout (`shutdown(30, TimeUnit.SECONDS)`).
    `Future<Void>` | `shutdown​(long timeout, TimeUnit unit)` | Initiate the server shutdown sequence.
    `default Future<Boolean>` | `updateSSLOptions​(ServerSSLOptions options)` | Update the server with new SSL `options`, the update happens if the options object is valid and different from the existing options object.
    `Future<Boolean>` | `updateSSLOptions​(ServerSSLOptions options, boolean force)` | Update the server with new SSL `options`, the update happens if the options object is valid and different from the existing options object.
    `Future<Boolean>` | `updateTrafficShapingOptions​(TrafficShapingOptions options)` | Update the server with new traffic `options`, the update happens if the options object is valid and different from the existing options object.

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

      `isMetricsEnabled`

- - ### Method Detail

    - #### connectHandler

          NetServer connectHandler​(Handler<NetSocket> handler)

      Supply a connect handler for this server. The server can only have at most one connect handler at any one time. As the server accepts TCP or SSL connections it creates an instance of `NetSocket` and passes it to the connect handler.
      Returns:
        a reference to this, so the API can be used fluently

    - #### connectHandler

          Handler<NetSocket> connectHandler()

    - #### listen

          Future<NetServer> listen()

      Start listening on the port and host as configured in the `NetServerOptions` used when creating the server.

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

      Returns:
        a future completed with the listen operation result

    - #### listen

          default Future<NetServer> listen​(int port,
                                           String host)

      Start listening on the specified port and host, ignoring port and host configured in the `NetServerOptions` used when creating the server.

      Port `0` can be specified meaning "choose an random port".

      Host `0.0.0.0` can be specified meaning "listen on all available interfaces".

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

      Returns:
        a future completed with the listen operation result

    - #### listen

          default Future<NetServer> listen​(int port)

      Start listening on the specified port and host "0.0.0.0", ignoring port and host configured in the `NetServerOptions` used when creating the server.

      Port `0` can be specified meaning "choose an random port".

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

      Returns:
        a future completed with the listen operation result

    - #### listen

          Future<NetServer> listen​(SocketAddress localAddress)

      Start listening on the specified local address, ignoring port and host configured in the `NetServerOptions` used when creating the server.

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

      Parameters:
        `localAddress` - the local address to listen on
      Returns:
        a future completed with the listen operation result

    - #### exceptionHandler

          NetServer exceptionHandler​(Handler<Throwable> handler)

      Set an exception handler called for socket errors happening before the connection is passed to the `connectHandler(io.vertx.core.Handler<io.vertx.core.net.NetSocket>)`, e.g during the TLS handshake.
      Parameters:
        `handler` - the handler to set
      Returns:
        a reference to this, so the API can be used fluently

    - #### close

          default Future<Void> close()

      Close the server. This will close any currently open connections. The close may not complete until after this method has returned.
      Returns:
        a future completed with the listen operation result

    - #### shutdown

          default Future<Void> shutdown()

      Shutdown with a 30 seconds timeout (`shutdown(30, TimeUnit.SECONDS)`).
      Returns:
        a future completed when shutdown has completed

    - #### shutdown

          Future<Void> shutdown​(long timeout,
                                TimeUnit unit)

      Initiate the server shutdown sequence.

      Connections are taken out of service and notified the close sequence has started through `NetSocket.shutdownHandler(Handler)`. When all connections are closed the client is closed. When the `timeout` expires, all unclosed connections are immediately closed.

      Parameters:
        `timeout` - the amount of time after which all resources are forcibly closed
        `unit` - the of the timeout
      Returns:
        a future notified when the client is closed

    - #### 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.

    - #### updateSSLOptions

          default Future<Boolean> updateSSLOptions​(ServerSSLOptions options)

      Update the server with new SSL `options`, the update happens if the options object is valid and different from the existing options object.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
        `options` - the new SSL options
      Returns:
        a future signaling the update success

    - #### updateSSLOptions

          Future<Boolean> updateSSLOptions​(ServerSSLOptions options,
                                           boolean force)

      Update the server with new SSL `options`, the update happens if the options object is valid and different from the existing options object.

      The `options` object is compared using its `equals` method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting `force` to `true` forces the update.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
        `options` - the new SSL options
        `force` - force the update when options are equals
      Returns:
        a future signaling the update success

    - #### updateTrafficShapingOptions

          Future<Boolean> updateTrafficShapingOptions​(TrafficShapingOptions options)

      Update the server with new traffic `options`, the update happens if the options object is valid and different from the existing options object.

      The `options` object is compared using its `equals` method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting `force` to `true` forces the update.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
        `options` - the new traffic shaping options
      Returns:
        a future signaling the update success