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
    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 notified when close is complete.
    `Handler<NetSocket>` | `connectHandler()`
    `NetServer` | `connectHandler(Handler<NetSocket> handler)` Supply a connect handler for this server.
    `ReadStream<NetSocket>` | `connectStream()` Return the connect stream 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.
    `NetServer` | `listen()` Start listening on the port and host as configured in the `NetServerOptions` used when creating the server.
    `NetServer` | `listen(Handler<AsyncResult<NetServer>> listenHandler)` Like `listen()` but providing a handler that will be notified when the server is listening, or fails.
    `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.
    `NetServer` | `listen(int port, Handler<AsyncResult<NetServer>> listenHandler)` Like `listen(int)` but providing a handler that will be notified when the server is listening, or fails.
    `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.
    `NetServer` | `listen(int port, String host, Handler<AsyncResult<NetServer>> listenHandler)` Like `listen(int, String)` but providing a handler that will be notified when the server is listening, or fails.
    `NetServer` | `listen(SocketAddress localAddress)` Start listening on the specified local address, ignoring port and host configured in the `NetServerOptions` used when creating the server.
    `NetServer` | `listen(SocketAddress localAddress, Handler<AsyncResult<NetServer>> listenHandler)` Like `listen(SocketAddress)` but providing a handler that will be notified when the server is listening, or fails.

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

      `isMetricsEnabled`

- - ### Method Detail

    - #### connectStream

          ReadStream<NetSocket> connectStream()

      Return the connect stream for this server. The server can only have at most one 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 stream `ReadStream.handler(io.vertx.core.Handler)`.
      Returns:
        the connect stream

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

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

    - #### listen

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

      Like `listen()` but providing a handler that will be notified when the server is listening, or fails.
      Parameters:
        `listenHandler` - handler that will be notified when listening or failed
      Returns:
        a reference to this, so the API can be used fluently

    - #### listen

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

    - #### listen

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

      Like `listen(int, String)` but providing a handler that will be notified when the server is listening, or fails.
      Parameters:
        `port` - the port to listen on
        `host` - the host to listen on
        `listenHandler` - handler that will be notified when listening or failed
      Returns:
        a reference to this, so the API can be used fluently

    - #### listen

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

    - #### listen

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

      Like `listen(int)` but providing a handler that will be notified when the server is listening, or fails.
      Parameters:
        `port` - the port to listen on
        `listenHandler` - handler that will be notified when listening or failed
      Returns:
        a reference to this, so the API can be used fluently

    - #### listen

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

    - #### listen

          NetServer listen(SocketAddress localAddress,
                           Handler<AsyncResult<NetServer>> listenHandler)

      Like `listen(SocketAddress)` but providing a handler that will be notified when the server is listening, or fails.
      Parameters:
        `localAddress` - the local address to listen on
        `listenHandler` - handler that will be notified when listening or failed
      Returns:
        a reference to this, so the API can be used fluently

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

          void close()

      Close the server. This will close any currently open connections. The close may not complete until after this method has returned.

    - #### close

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

      Like `close()` but supplying a handler that will be notified when close is complete.
      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 © 2021 Eclipse. All rights reserved.