java.lang.Object
net.i2p.i2ptunnel.udp.UDPSink
- All Implemented Interfaces:
Sink
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final InetAddressThe address datagrams are sent to.protected final intThe port datagrams are sent to.protected final DatagramSocketThe socket datagrams are written to.Constructor Summary
ConstructorsConstructorDescriptionUDPSink(DatagramSocket socket, InetAddress host, int port) Sends datagrams through the given socket to the specified host and port.UDPSink(InetAddress host, int port) Opens a DatagramSocket and sends datagrams to the given host and port.Method Summary
All MethodsModifier and TypeMethodDescriptionintgetPort()Local port of the DatagramSocket we are sending from.Returns the underlying DatagramSocket for use byUDPSourceconstructor.voidsend(Destination src, int fromPort, int toPort, byte[] data) Sends the data to the configured remote host and port.voidstop()Closes the underlying DatagramSocket.
Field Details
sock
The socket datagrams are written to.remoteHost
The address datagrams are sent to.remotePort
protected final int remotePortThe port datagrams are sent to.
Constructor Details
UDPSink
Opens a DatagramSocket and sends datagrams to the given host and port.- Parameters:
host- where to sendport- where to send- Throws:
IllegalArgumentException- on DatagramSocket IOException
UDPSink
Sends datagrams through the given socket to the specified host and port.- Parameters:
socket- the socket to send through, owned by the callerhost- where to sendport- where to send
Method Details
send
Sends the data to the configured remote host and port.- Specified by:
sendin interfaceSink- Parameters:
src- unused; a datagram carries no source addressfromPort- unused; the local port is fixed at constructiontoPort- unused; the remote port is fixed at constructiondata- 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
Returns the underlying DatagramSocket for use byUDPSourceconstructor.- Returns:
- the DatagramSocket to hand to the matching UDPSource
stop
public void stop()Closes the underlying DatagramSocket.