java.lang.Object
net.i2p.i2ptunnel.udp.UDPSink
All Implemented Interfaces:
Sink

public class UDPSinkextends Object implements Sink
UDP sink implementation for streaming data.
  • Field Details

    • sock

      protected final DatagramSocket sock
      The socket datagrams are written to.
    • remoteHost

      protected final InetAddress remoteHost
      The address datagrams are sent to.
    • remotePort

      protected final int remotePort
      The port datagrams are sent to.
  • Constructor Details

    • UDPSink

      public UDPSink(InetAddress host, int port)
      Opens a DatagramSocket and sends datagrams to the given host and port.
      Parameters:
      host - where to send
      port - where to send
      Throws:
      IllegalArgumentException - on DatagramSocket IOException
    • UDPSink

      public UDPSink(DatagramSocket socket, InetAddress host, int port)
      Sends datagrams through the given socket to the specified host and port.
      Parameters:
      socket - the socket to send through, owned by the caller
      host - where to send
      port - where to send
  • Method Details

    • send

      public void send(Destination src, int fromPort, int toPort, byte[] data)
      Sends the data to the configured remote host and port.
      Specified by:
      send in interface Sink
      Parameters:
      src - unused; a datagram carries no source address
      fromPort - unused; the local port is fixed at construction
      toPort - unused; the remote port is fixed at construction
      data - the datagram payload to deliver to the destination
      Throws:
      RuntimeException - on DatagramSocket IOException
    • getPort

      public int getPort()
      Local port of the DatagramSocket we are sending from.
      Returns:
      the local port of the DatagramSocket we are sending from
    • getSocket

      public DatagramSocket getSocket()
      Returns the underlying DatagramSocket for use by UDPSource constructor.
      Returns:
      the DatagramSocket to hand to the matching UDPSource
    • stop

      public void stop()
      Closes the underlying DatagramSocket.