java.lang.Object
net.i2p.i2ptunnel.udp.UDPSource
Field Summary
Modifier and TypeFieldDescriptionstatic final intMaximum UDP packet size.private final intThe local port this source is bound to.protected SinkThe consumer each received datagram is passed to.protected final DatagramSocketThe socket datagrams are read from.protected final ThreadThe thread that reads from the socket and forwards to the sink.Constructor Summary
ConstructorsConstructorDescriptionUDPSource(int port) Creates a source listening on the specified port.UDPSource(DatagramSocket sock) Creates a source using an existing socket (e.g., fromUDPSink).Method Summary
All MethodsModifier and TypeMethodDescriptionintgetPort()Local port of the DatagramSocket we are receiving on.voidrun()Receives UDP datagrams in a loop and forwards them to the configured sink.voidSets the sink for received UDP datagrams.voidstart()Starts the source thread to begin receiving UDP datagrams.voidstop()Stops the source thread and closes the socket.
Field Details
sock
The socket datagrams are read from.sink
The consumer each received datagram is passed to.thread
The thread that reads from the socket and forwards to the sink.port
private final int portThe local port this source is bound to.MAX_SIZE
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
Creates a source using an existing socket (e.g., fromUDPSink).- Parameters:
sock- the DatagramSocket to receive on
Method Details
setSink
start
run
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.