org.fourthline.cling.transport.spi

## Interface StreamServer<C extends StreamServerConfiguration>

- Type Parameters:
    `C` - The type of the service's configuration.
  All Superinterfaces:
    Runnable
  All Known Implementing Classes:
    AsyncServletStreamServerImpl, StreamServerImpl

      public interface StreamServer<C extends StreamServerConfiguration>
      extends Runnable

  Service for receiving TCP (HTTP) streams, one per bound IP address.

  This service typically listens on a socket for TCP connections.

  This listening loop is started with the `run()` method, this service is `Runnable`. Then `Router.received(UpnpStream)` is called with a custom `UpnpStream`. This will start processing of the request and `run()` the `UpnpStream` (which is also `Runnable`) in a separate thread, freeing up the receiving thread immediately.

  The `UpnpStream` then creates a `StreamRequestMessage` and calls the `UpnpStream.process(org.fourthline.cling.model.message.StreamRequestMessage)` method. The `UpnpStream` then returns the response to the network client.

  In pseudo-code:

       MyStreamServer implements StreamServer {
            run() {
                while (not stopped) {
                    Connection con = listenToSocketAndBlock();
                    router.received( new MyUpnpStream(con) );
                }
            }
       }

       MyUpnpStream(con) extends UpnpStream {
            run() {
                try {
                    StreamRequestMessage request = // ... Read request
                    StreamResponseMessage response = process(request);
                    // ... Send response
                    responseSent(response))
                } catch (Exception ex) {
                    responseException(ex);
                }
            }
       }

  An implementation has to be thread-safe.

  Author:
    Christian Bauer

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `C` | `getConfiguration()`
    `int` | `getPort()` This method will be called potentially right after `init(java.net.InetAddress, org.fourthline.cling.transport.Router)`, the actual assigned local port must be available before the server is started.
    `void` | `init(InetAddress bindAddress, Router router)` Configures the service and starts any listening sockets.
    `void` | `stop()` Stops the service, closes any listening sockets.

    - ### Methods inherited from interface java.lang.Runnable

      `run`

- - ### Method Detail

    - #### init

          void init(InetAddress bindAddress,
                    Router router)
             throws InitializationException

      Configures the service and starts any listening sockets.
      Parameters:
        `bindAddress` - The address to bind any sockets on.
        `router` - The router which handles the incoming `UpnpStream`.
      Throws:
        `InitializationException` - If the service could not be initialized or started.

    - #### getPort

          int getPort()

      This method will be called potentially right after `init(java.net.InetAddress, org.fourthline.cling.transport.Router)`, the actual assigned local port must be available before the server is started.
      Returns:
        The TCP port this service is listening on, e.g. the actual ephemeral port.

    - #### stop

          void stop()

      Stops the service, closes any listening sockets.

    - #### getConfiguration

          C getConfiguration()

      Returns:
        This service's configuration.

Copyright © 2016 4th Line GmbH, Switzerland. All rights reserved.