org.vertx.java.core.net

## Interface NetClient

-     public interface NetClient

  A TCP/SSL client.

  Multiple connections to different servers can be made using the same instance.

  This client supports a configurable number of connection attempts and a configurable delay between attempts.

  If an instance is instantiated from an event loop then the handlers of the instance will always be called on that same event loop. If an instance is instantiated from some other arbitrary Java thread then an event loop will be assigned to the instance and used when any of its handlers are called.

  Instances cannot be used from worker verticles

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Close the client.
    `NetClient` | `connect(int port, Handler<NetSocket> connectCallback)` Attempt to open a connection to a server at the specific `port` and host `localhost` The connect is done asynchronously and on success, a `NetSocket` instance is supplied via the `connectHandler` instance
    `NetClient` | `connect(int port, java.lang.String host, Handler<NetSocket> connectHandler)` Attempt to open a connection to a server at the specific `port` and `host`.
    `void` | `exceptionHandler(Handler<java.lang.Exception> handler)` Set the exception handler.
    `java.lang.Integer` | `getBossThreads()`
    `java.lang.Long` | `getConnectTimeout()`
    `java.lang.String` | `getKeyStorePassword()`
    `java.lang.String` | `getKeyStorePath()`
    `java.lang.Integer` | `getReceiveBufferSize()`
    `int` | `getReconnectAttempts()` Get the number of reconnect attempts
    `long` | `getReconnectInterval()` Get the reconnect interval, in milliseconds.
    `java.lang.Integer` | `getSendBufferSize()`
    `java.lang.Integer` | `getTrafficClass()`
    `java.lang.String` | `getTrustStorePassword()`
    `java.lang.String` | `getTrustStorePath()`
    `java.lang.Boolean` | `isReuseAddress()`
    `java.lang.Boolean` | `isSoLinger()`
    `boolean` | `isSSL()`
    `java.lang.Boolean` | `isTCPKeepAlive()`
    `java.lang.Boolean` | `isTCPNoDelay()`
    `boolean` | `isTrustAll()`
    `NetClient` | `setBossThreads(int threads)` Set the number of boss threads to use.
    `NetClient` | `setConnectTimeout(long timeout)` Set the connect timeout in milliseconds.
    `NetClient` | `setKeyStorePassword(java.lang.String pwd)` Set the password for the SSL key store.
    `NetClient` | `setKeyStorePath(java.lang.String path)` Set the path to the SSL key store.
    `NetClient` | `setReceiveBufferSize(int size)` Set the TCP receive buffer size for connections created by this instance to `size` in bytes.
    `NetClient` | `setReconnectAttempts(int attempts)` Set the number of reconnection attempts.
    `NetClient` | `setReconnectInterval(long interval)` Set the reconnect interval, in milliseconds
    `NetClient` | `setReuseAddress(boolean reuse)` Set the TCP reuseAddress setting for connections created by this instance to `reuse`.
    `NetClient` | `setSendBufferSize(int size)` Set the TCP send buffer size for connections created by this instance to `size` in bytes.
    `NetClient` | `setSoLinger(boolean linger)` Set the TCP soLinger setting for connections created by this instance to `linger`.
    `NetClient` | `setSSL(boolean ssl)` If `ssl` is `true`, this signifies that any connections will be SSL connections.
    `NetClient` | `setTCPKeepAlive(boolean keepAlive)` Set the TCP keepAlive setting for connections created by this instance to `keepAlive`.
    `NetClient` | `setTCPNoDelay(boolean tcpNoDelay)` If `tcpNoDelay` is set to `true` then Nagle's algorithm will turned off for the TCP connections created by this instance.
    `NetClient` | `setTrafficClass(int trafficClass)` Set the TCP trafficClass setting for connections created by this instance to `trafficClass`.
    `NetClient` | `setTrustAll(boolean trustAll)` If you want an SSL client to trust *all* server certificates rather than match them against those in its trust store, you can set this to true.
    `NetClient` | `setTrustStorePassword(java.lang.String pwd)` Set the password for the SSL trust store.
    `NetClient` | `setTrustStorePath(java.lang.String path)` Set the path to the SSL trust store.

- - ### Method Detail

    - #### connect

          NetClient connect(int port,
                          Handler<NetSocket> connectCallback)

      Attempt to open a connection to a server at the specific `port` and host `localhost` The connect is done asynchronously and on success, a `NetSocket` instance is supplied via the `connectHandler` instance
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### connect

          NetClient connect(int port,
                          java.lang.String host,
                          Handler<NetSocket> connectHandler)

      Attempt to open a connection to a server at the specific `port` and `host`. `host` can be a valid host name or IP addresss. The connect is done asynchronously and on success, a `NetSocket` instance is supplied via the `connectHandler` instance
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### close

          void close()

      Close the client. Any sockets which have not been closed manually will be closed here.

    - #### setReconnectAttempts

          NetClient setReconnectAttempts(int attempts)

      Set the number of reconnection attempts. In the event a connection attempt fails, the client will attempt to connect a further number of times, before it fails. Default value is zero.

    - #### getReconnectAttempts

          int getReconnectAttempts()

      Get the number of reconnect attempts

    - #### setReconnectInterval

          NetClient setReconnectInterval(long interval)

      Set the reconnect interval, in milliseconds

    - #### getReconnectInterval

          long getReconnectInterval()

      Get the reconnect interval, in milliseconds.

    - #### exceptionHandler

          void exceptionHandler(Handler<java.lang.Exception> handler)

      Set the exception handler. Any exceptions that occur during connect or later on will be notified via the `handler`. If no handler is supplied any exceptions will be printed to `System.err`

    - #### setSSL

          NetClient setSSL(boolean ssl)

      If `ssl` is `true`, this signifies that any connections will be SSL connections.
      Returns:
        A reference to this, so multiple invocations can be chained together.

    - #### setKeyStorePath

          NetClient setKeyStorePath(java.lang.String path)

      Set the path to the SSL key store. This method should only be used in SSL mode, i.e. after `setSSL(boolean)` has been set to `true`.

      The SSL key store is a standard Java Key Store, and will contain the client certificate. Client certificates are only required if the server requests client authentication.

      Returns:
        A reference to this, so multiple invocations can be chained together.

    - #### setKeyStorePassword

          NetClient setKeyStorePassword(java.lang.String pwd)

      Set the password for the SSL key store. This method should only be used in SSL mode, i.e. after `setSSL(boolean)` has been set to `true`.

      Returns:
        A reference to this, so multiple invocations can be chained together.

    - #### setTrustStorePath

          NetClient setTrustStorePath(java.lang.String path)

      Set the path to the SSL trust store. This method should only be used in SSL mode, i.e. after `setSSL(boolean)` has been set to `true`.

      The trust store is a standard Java Key Store, and should contain the certificates of any servers that the client trusts. If you wish the client to trust all server certificates you can use the `setTrustAll(boolean)` method.

      Returns:
        A reference to this, so multiple invocations can be chained together.

    - #### setTrustStorePassword

          NetClient setTrustStorePassword(java.lang.String pwd)

      Set the password for the SSL trust store. This method should only be used in SSL mode, i.e. after `setSSL(boolean)` has been set to `true`.

      Returns:
        A reference to this, so multiple invocations can be chained together.

    - #### setTrustAll

          NetClient setTrustAll(boolean trustAll)

      If you want an SSL client to trust *all* server certificates rather than match them against those in its trust store, you can set this to true.

      Use this with caution as you may be exposed to "main in the middle" attacks

      Parameters:
        `trustAll` - Set to true if you want to trust all server certificates

    - #### setTCPNoDelay

          NetClient setTCPNoDelay(boolean tcpNoDelay)

      If `tcpNoDelay` is set to `true` then Nagle's algorithm will turned off for the TCP connections created by this instance.
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### setSendBufferSize

          NetClient setSendBufferSize(int size)

      Set the TCP send buffer size for connections created by this instance to `size` in bytes.
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### setReceiveBufferSize

          NetClient setReceiveBufferSize(int size)

      Set the TCP receive buffer size for connections created by this instance to `size` in bytes.
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### setTCPKeepAlive

          NetClient setTCPKeepAlive(boolean keepAlive)

      Set the TCP keepAlive setting for connections created by this instance to `keepAlive`.
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### setReuseAddress

          NetClient setReuseAddress(boolean reuse)

      Set the TCP reuseAddress setting for connections created by this instance to `reuse`.
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### setSoLinger

          NetClient setSoLinger(boolean linger)

      Set the TCP soLinger setting for connections created by this instance to `linger`.
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### setTrafficClass

          NetClient setTrafficClass(int trafficClass)

      Set the TCP trafficClass setting for connections created by this instance to `trafficClass`.
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### setConnectTimeout

          NetClient setConnectTimeout(long timeout)

      Set the connect timeout in milliseconds.
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### setBossThreads

          NetClient setBossThreads(int threads)

      Set the number of boss threads to use. Boss threads are used to make connections.
      Returns:
        a reference to this so multiple method calls can be chained together

    - #### isTCPNoDelay

          java.lang.Boolean isTCPNoDelay()

      Returns:
        true if Nagle's algorithm is disabled.

    - #### getSendBufferSize

          java.lang.Integer getSendBufferSize()

      Returns:
        The TCP send buffer size

    - #### getReceiveBufferSize

          java.lang.Integer getReceiveBufferSize()

      Returns:
        The TCP receive buffer size

    - #### isTCPKeepAlive

          java.lang.Boolean isTCPKeepAlive()

      Returns:
        true if TCP keep alive is enabled

    - #### isReuseAddress

          java.lang.Boolean isReuseAddress()

      Returns:
        The value of TCP reuse address

    - #### isSoLinger

          java.lang.Boolean isSoLinger()

      Returns:
        the value of TCP so linger

    - #### getTrafficClass

          java.lang.Integer getTrafficClass()

      Returns:
        the value of TCP traffic class

    - #### getConnectTimeout

          java.lang.Long getConnectTimeout()

      Returns:
        The connect timeout in milliseconds

    - #### getBossThreads

          java.lang.Integer getBossThreads()

      Returns:
        The number of boss threads

    - #### isSSL

          boolean isSSL()

      Returns:
        true if this client will make SSL connections

    - #### isTrustAll

          boolean isTrustAll()

      Returns:
        true if this client will trust all server certificates.

    - #### getKeyStorePath

          java.lang.String getKeyStorePath()

      Returns:
        The path to the key store

    - #### getKeyStorePassword

          java.lang.String getKeyStorePassword()

      Returns:
        The keystore password

    - #### getTrustStorePath

          java.lang.String getTrustStorePath()

      Returns:
        The trust store path

    - #### getTrustStorePassword

          java.lang.String getTrustStorePassword()

      Returns:
        The trust store password