net.i2p.i2ptunnel.udp

## Class UDPSource

- java.lang.Object
- - net.i2p.i2ptunnel.udp.UDPSource

- All Implemented Interfaces:
    Runnable, Source

      public class UDPSource
      extends Object
      implements Source, Runnable

  UDP source implementation for streaming data.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `MAX_SIZE`
    `protected Sink` | `sink`
    `protected DatagramSocket` | `sock`
    `protected Thread` | `thread`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UDPSource(DatagramSocket sock)` use socket from UDPSink
    `UDPSource(int port)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getPort()`
    `void` | `run()`
    `void` | `setSink(Sink sink)` Sets the sink for received UDP datagrams.
    `void` | `start()` Starts the source thread to begin receiving UDP datagrams.
    `void` | `stop()` Stops the source thread and closes the socket.

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

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

- - ### Field Detail

    - #### MAX_SIZE

          public static final int MAX_SIZE

      See Also:
        Constant Field Values

    - #### sink

          protected Sink sink

    - #### sock

          protected final DatagramSocket sock

    - #### thread

          protected final Thread thread

  - ### Constructor Detail

    - #### UDPSource

          public UDPSource(DatagramSocket sock)

      use socket from UDPSink

    - #### UDPSource

          public UDPSource(int port)

      Throws:
        `RuntimeException` - on DatagramSocket IOException

  - ### Method Detail

    - #### getPort

          public int getPort()

      Returns:
        the local port of the DatagramSocket we are receiving on

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`

    - #### setSink

          public void setSink(Sink sink)

      Sets the sink for received UDP datagrams.
      Specified by:
        `setSink` in interface `Source`
      Parameters:
        `sink` - the sink to receive processed datagrams

    - #### start

          public void start()

      Starts the source thread to begin receiving UDP datagrams.
      Specified by:
        `start` in interface `Source`

    - #### stop

          public void stop()

      Stops the source thread and closes the socket.