Schnittstelle DatagramIO<C extends DatagramIOConfiguration>

Typparameter:
C - The type of the service's configuration.
Alle Superschnittstellen:
Runnable
Alle bekannten Implementierungsklassen:
DatagramIOImpl

public interface DatagramIO<C extends DatagramIOConfiguration> extends Runnable
Service for receiving (unicast only) and sending UDP datagrams, one per bound IP address.

This service typically listens on a socket for UDP unicast datagrams, with an ephemeral port.

This listening loop is started with the run() method, this service is Runnable. Any received datagram is then converted into an IncomingDatagramMessage and handled by the Router.received(org.jupnp.model.message.IncomingDatagramMessage) method. This conversion is the job of the DatagramProcessor.

Clients of this service use it to send UDP datagrams, either to a unicast or multicast destination. Any OutgoingDatagramMessage can be converted and written into a datagram with the DatagramProcessor.

An implementation has to be thread-safe.

Autor:
Christian Bauer, Kai Kreuzer - added multicast response port
  • Methodendetails

    • init

      void init(InetAddress bindAddress, int bindPort, Router router, DatagramProcessor datagramProcessor) throws InitializationException
      Configures the service and starts any listening sockets.
      Parameter:
      bindAddress - The port to bind any sockets on. 0 means choosing an ephemeral port
      router - The router which handles received IncomingDatagramMessages.
      datagramProcessor - Reads and writes datagrams.
      Löst aus:
      InitializationException - If the service could not be initialized or started.
    • stop

      void stop()
      Stops the service, closes any listening sockets.
    • getConfiguration

      C getConfiguration()
      Gibt zurück:
      This service's configuration.
    • send

      void send(OutgoingDatagramMessage message)
      Parameter:
      message - The message to send.
    • send

      void send(DatagramPacket datagram)
      The actual sending of a UDP datagram.

      Recoverable errors should be logged, if appropriate only with debug level. Any non-recoverable errors should be thrown as RuntimeExceptions.

      Parameter:
      datagram - The UDP datagram to send.