com.jscape.inet.ipclient

## Class IpClient

- java.lang.Object
- - com.jscape.inet.ipclient.IpClient

- All Implemented Interfaces:
    java.lang.AutoCloseable
  Direct Known Subclasses:
    IpClientSsh, IpClientSsl

      public class IpClient
      extends java.lang.Object
      implements java.lang.AutoCloseable

  Implements basic functionality of a TCP/IP client connection.

  Example usage:

       try {
         // create new IpClient instance with hostname, port and timeout arguments
         IpClient client = new IpClient("10.0.0.1",53,5000);

         // establish connection with server
         client.connect();

         // obtain OutputStream for sending data to server
         OutputStream out = client.getOutputStream();

         // obtain InputStream for reading data from server
         InputStream in = client.getInputStream();

         // disconnect from server
         client.disconnect();

       } catch(IpClientException ipe) {
         ipe.printStackTrace();
       }

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `IpClient(java.lang.String hostname, int port)` Creates a new IpClient instance.
    `IpClient(java.lang.String hostname, int port, int timeout)` Creates a new IpClient instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addIpClientListener(IpClientListener listener)` Adds IpClient event listener.
    `void` | `clearProxySettings()` Clears proxy server values.
    `void` | `close()`
    `IpClient` | `connect()` Establishes connection with server.
    `void` | `disconnect()` Closes connection with server.
    `int` | `getConnectTimeout()` Gets the timeout used when opening a server connection.
    `java.io.InputStream` | `getInputStream()` Gets InputStream from socket connection established with server.
    `java.io.OutputStream` | `getOutputStream()` Gets OutputStream from socket connection established with server.
    `int` | `getReadTimeout()` Gets the timeout used when reading responses from server.
    `java.net.Socket` | `getSocket()` Gets Socket established after invoking the IpClient#connect method.
    `void` | `removeIpClientListener(IpClientListener listener)` Removes an IpClient event listener.
    `void` | `setConnectTimeout(int timeout)` Sets the timeout for opening a server connection.
    `void` | `setInputStream(java.io.InputStream input)` Replaces InputStream from socket connection established with server.
    `void` | `setOutputStream(java.io.OutputStream output)` Sets OutputStream from socket connection established with server.
    `void` | `setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)` Sets the username and password to use when for authentication with proxy server.
    `void` | `setProxyHost(java.lang.String proxyHostname, int proxyPort)` Sets the proxy hostname and port for this connection.
    `void` | `setProxyType(java.lang.String proxyType)` Sets the proxy type will be used for this connection.
    `void` | `setReadTimeout(int timeout)` Sets the timeout for reading responses from server.
    `void` | `setSocket(java.net.Socket socket)` Sets socket replacing current socket with new socket.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### IpClient

          public IpClient(java.lang.String hostname,
                          int port)

      Creates a new IpClient instance.
      Parameters:
        `hostname` - the server hostname or IP address
        `port` - the server port

    - #### IpClient

          public IpClient(java.lang.String hostname,
                          int port,
                          int timeout)

      Creates a new IpClient instance.
      Parameters:
        `hostname` - the server hostname or IP address
        `port` - the server port
        `timeout` - the timeout for establishing a connection specified in ms (milliseconds)

  - ### Method Detail

    - #### setConnectTimeout

          public void setConnectTimeout(int timeout)

      Sets the timeout for opening a server connection.

      Default is 30 seconds.
      Parameters:
        `timeout` - the timeout in milliseconds

    - #### getConnectTimeout

          public int getConnectTimeout()

      Gets the timeout used when opening a server connection.

      Default is 30 seconds.
      Returns:
        timeout server connection.

    - #### setInputStream

          public void setInputStream(java.io.InputStream input)

      Replaces InputStream from socket connection established with server. IpClient#connect method must be invoked prior to invoking this method.
      Parameters:
        `input` - The input stream instance

    - #### getInputStream

          public java.io.InputStream getInputStream()

      Gets InputStream from socket connection established with server. IpClient#connect method must be invoked prior to invoking this method.
      Returns:
        an InputStream or null if connection has been closed or not yet established

    - #### setOutputStream

          public void setOutputStream(java.io.OutputStream output)

      Sets OutputStream from socket connection established with server.
      Parameters:
        `output` - The output stream instance

    - #### getOutputStream

          public java.io.OutputStream getOutputStream()

      Gets OutputStream from socket connection established with server. IpClient#connect method must be invoked prior to invoking this method.
      Returns:
        an OutputStream or null if connection has been closed or not yet established

    - #### setReadTimeout

          public void setReadTimeout(int timeout)

      Sets the timeout for reading responses from server. Default is 30 seconds.
      Parameters:
        `timeout` - the timeout in milliseconds

    - #### getReadTimeout

          public int getReadTimeout()

      Gets the timeout used when reading responses from server. Default is 30 seconds.
      Returns:
        reading from server timeout.

    - #### setSocket

          public void setSocket(java.net.Socket socket)
                         throws IpClientException

      Sets socket replacing current socket with new socket.
      Parameters:
        `socket` - the new socket
      Throws:
        `IpClientException` - if a I/O error occurs.

    - #### getSocket

          public java.net.Socket getSocket()

      Gets Socket established after invoking the IpClient#connect method.
      Returns:
        a Socket
      See Also:
        `connect()`

    - #### setProxyAuthentication

          public void setProxyAuthentication(java.lang.String proxyUsername,
                                             java.lang.String proxyPassword)

      Sets the username and password to use when for authentication with proxy server. To clear these settings invoke the `#clearProxySettings` method.
      Parameters:
        `proxyUsername` - the proxy username
        `proxyPassword` - the proxy password
      See Also:
        `clearProxySettings()`

    - #### setProxyHost

          public void setProxyHost(java.lang.String proxyHostname,
                                   int proxyPort)

      Sets the proxy hostname and port for this connection. To clear these settings invoke the `#clearProxySettings` method.
      Parameters:
        `proxyHostname` - the hostname or ip address of the proxy server
        `proxyPort` - the port of the proxy server
      See Also:
        `clearProxySettings()`

    - #### setProxyType

          public void setProxyType(java.lang.String proxyType)

      Sets the proxy type will be used for this connection.
      Parameters:
        `proxyType` - The proxy type. Valid values: HTTP, SOCKS5

    - #### clearProxySettings

          public void clearProxySettings()

      Clears proxy server values.

    - #### addIpClientListener

          public void addIpClientListener(IpClientListener listener)

      Adds IpClient event listener.
      Parameters:
        `listener` - an IpClientListener

    - #### connect

          public IpClient connect()
                           throws IpClientException

      Establishes connection with server.
      Throws:
        `IpClientException` - if an I/O or network related error occurs

    - #### disconnect

          public void disconnect()
                          throws IpClientException

      Closes connection with server.
      Throws:
        `IpClientException` - if an I/O or network related error occurs

    - #### close

          public void close()
                     throws java.lang.Exception

      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Throws:
        `java.lang.Exception`

    - #### removeIpClientListener

          public void removeIpClientListener(IpClientListener listener)

      Removes an IpClient event listener.
      Parameters:
        `listener` - an IpClientListener

Copyright © JSCAPE LLC. 1999-2021. All Rights Reserved