org.cybergarage.http

## Class HTTPServer

- java.lang.Object
- - org.cybergarage.http.HTTPServer

- All Implemented Interfaces:
    Runnable

      public class HTTPServer
      extends Object
      implements Runnable

  HTTP server implementation for the CyberLink HTTP framework.

  This class provides a multithreaded HTTP server that can:

  - Accept incoming HTTP connections
  - Dispatch requests to registered listeners
  - Handle multiple concurrent connections
  - Support both IPv4 and IPv6 addresses

  The server must be initialized using `open(InetAddress, int)` or `open(String, int)` before starting. Optionally, `HTTPRequestListener` instances can be registered to handle incoming requests.

  Version:
    1.8

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_PORT`
    `static int` | `DEFAULT_TIMEOUT` Default timeout connection for HTTP comunication
    `static String` | `NAME` Constants
    `protected int` | `timeout` Store the current TCP timeout value The variable should be accessed by getter and setter metho
    `static String` | `VERSION`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HTTPServer()` Creates a new HTTP server instance.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Socket` | `accept()` Accepts an incoming connection from the server socket.
    `void` | `addRequestListener(HTTPRequestListener listener)` Adds a request listener to receive HTTP request notifications.
    `boolean` | `close()` Closes the server socket and cleans up resources.
    `String` | `getBindAddress()` Gets the bind address as a string.
    `int` | `getBindPort()` Gets the bind port.
    `static String` | `getName()`
    `ServerSocket` | `getServerSock()` Gets the server socket.
    `int` | `getTimeout()` Gets the current socket timeout value.
    `boolean` | `isOpened()` Checks if the server socket is opened.
    `boolean` | `open(InetAddress addr, int port)` Opens the server on specified address and port.
    `boolean` | `open(String addr, int port)` Opens the server on specified port with default bind address.
    `void` | `performRequestListener(HTTPRequest httpReq)` Notifies all registered request listeners of an HTTP request.
    `void` | `removeRequestListener(HTTPRequestListener listener)` Removes a request listener.
    `void` | `run()`
    `void` | `setTimeout(int timeout)` Sets the socket timeout value.
    `boolean` | `start()` Starts the HTTP server thread.
    `boolean` | `stop()` Stops the HTTP server thread.
    `String` | `toString()` Returns the bind address as string representation.

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_PORT

          public static final int DEFAULT_PORT

      See Also:
        Constant Field Values

    - #### DEFAULT_TIMEOUT

          public static final int DEFAULT_TIMEOUT

      Default timeout connection for HTTP comunication
      See Also:
        Constant Field Values

    - #### NAME

          public static final String NAME

      Constants
      See Also:
        Constant Field Values

    - #### timeout

          protected int timeout

      Store the current TCP timeout value The variable should be accessed by getter and setter metho

    - #### VERSION

          public static final String VERSION

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### HTTPServer

          public HTTPServer()

      Creates a new HTTP server instance. The server must be opened before it can accept connections.

  - ### Method Detail

    - #### accept

          public Socket accept()

      Accepts an incoming connection from the server socket.
      Returns:
        accepted socket with timeout set, or null if no server socket

    - #### addRequestListener

          public void addRequestListener(HTTPRequestListener listener)

      Adds a request listener to receive HTTP request notifications.
      Parameters:
        `listener` - the request listener to add

    - #### close

          public boolean close()

      Closes the server socket and cleans up resources.
      Returns:
        true if server was closed successfully, false otherwise

    - #### getBindAddress

          public String getBindAddress()

      Gets the bind address as a string.
      Returns:
        the bind address string, or empty string if not bound

    - #### getBindPort

          public int getBindPort()

      Gets the bind port.
      Returns:
        bind port number

    - #### getName

          public static String getName()

    - #### getServerSock

          public ServerSocket getServerSock()

      Gets the server socket.
      Returns:
        the ServerSocket instance

    - #### getTimeout

          public int getTimeout()

      Gets the current socket timeout value.
      Returns:
        timeout in milliseconds

    - #### isOpened

          public boolean isOpened()

      Checks if the server socket is opened.
      Returns:
        true if the server socket is not null

    - #### open

          public boolean open(InetAddress addr,
                              int port)

      Opens the server on specified address and port.
      Parameters:
        `addr` - bind address for the server
        `port` - port number to bind to
      Returns:
        true if server was opened successfully, false otherwise

    - #### open

          public boolean open(String addr,
                              int port)

      Opens the server on specified port with default bind address.
      Parameters:
        `addr` - bind address as hostname or IP address string
        `port` - port number to bind to
      Returns:
        true if server was opened successfully, false otherwise

    - #### performRequestListener

          public void performRequestListener(HTTPRequest httpReq)

      Notifies all registered request listeners of an HTTP request.
      Parameters:
        `httpReq` - the HTTP request to notify listeners about

    - #### removeRequestListener

          public void removeRequestListener(HTTPRequestListener listener)

      Removes a request listener.
      Parameters:
        `listener` - the request listener to remove

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`

    - #### setTimeout

          public void setTimeout(int timeout)

      Sets the socket timeout value.
      Parameters:
        `timeout` - timeout in milliseconds

    - #### start

          public boolean start()

      Starts the HTTP server thread.
      Returns:
        true if started successfully

    - #### stop

          public boolean stop()

      Stops the HTTP server thread.
      Returns:
        true if stopped successfully

    - #### toString

          public String toString()

      Returns the bind address as string representation.
      Overrides:
        `toString` in class `Object`
      Returns:
        bind address string