java.lang.Object
net.i2p.i2ptunnel.udp.UDPSource
All Implemented Interfaces:
Runnable, Source

public class UDPSourceextends Object implements Source, Runnable
UDP source implementation for streaming data.
  • Field Summary

    Modifier and Type
    Field
    Description
    static final int
    Maximum UDP packet size.
    private final int
    The local port this source is bound to.
    protected Sink
    The consumer each received datagram is passed to.
    protected final DatagramSocket
    The socket datagrams are read from.
    protected final Thread
    The thread that reads from the socket and forwards to the sink.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UDPSource(int port)
    Creates a source listening on the specified port.
    Creates a source using an existing socket (e.g., from UDPSink).
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    int
    Local port of the DatagramSocket we are receiving on.
    void
    run()
    Receives UDP datagrams in a loop and forwards them to the configured sink.
    void
    setSink(Sink sink)
    Sets the sink for received UDP datagrams.
    void
    Starts the source thread to begin receiving UDP datagrams.
    void
    Stops the source thread and closes the socket.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • sock

      protected final DatagramSocket sock
      The socket datagrams are read from.
    • sink

      protected Sink sink
      The consumer each received datagram is passed to.
    • thread

      protected final Thread thread
      The thread that reads from the socket and forwards to the sink.
    • port

      private final int port
      The local port this source is bound to.
    • MAX_SIZE

      public static final int MAX_SIZE
      Maximum UDP packet size.
      See Also:
  • Constructor Details

    • UDPSource

      public UDPSource(int port)
      Creates a source listening on the specified port.
      Parameters:
      port - the local UDP port to listen on
      Throws:
      RuntimeException - if the DatagramSocket cannot be opened
    • UDPSource

      public UDPSource(DatagramSocket sock)
      Creates a source using an existing socket (e.g., from UDPSink).
      Parameters:
      sock - the DatagramSocket to receive on
  • Method Details

    • 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
    • run

      public void run()
      Receives UDP datagrams in a loop and forwards them to the configured sink.
      Specified by:
      run in interface Runnable
    • getPort

      public int getPort()
      Local port of the DatagramSocket we are receiving on.
      Returns:
      the local port of the DatagramSocket we are receiving on
    • stop

      public void stop()
      Stops the source thread and closes the socket.