Package de.das.encrypter.comm
Class UdpReceiver
java.lang.Object
java.lang.Thread
de.das.encrypter.comm.UdpReceiver
- All Implemented Interfaces:
Runnable
The class provides a receiver service for UDP data packets on a specific port
that continuously waits for incoming data and forwards it to the registered
data receiver.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionUdpReceiver(int port, DataReceiver recv) Creates a new instance of the UDP receiver.UdpReceiver(String name, int port, DataReceiver recv) Creates a new instance of the UDP receiver. -
Method Summary
Modifier and TypeMethodDescriptionvoidkill()Sets the killed-flag, closes the socket and performs an interrupt.voidrun()Heart of the thread.voidsetDataReceiver(DataReceiver dataReceiver) Set an instance which wants to get the received data.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
UdpReceiver
Creates a new instance of the UDP receiver.- Parameters:
port- the port that will be listened to.recv- the data expecting DataReceiver instance.- Throws:
Exception- if the datagram socket couldn't be established.
-
UdpReceiver
Creates a new instance of the UDP receiver.- Parameters:
name- a name for the receiver.port- the port that will be listened to.recv- the data expecting DataReceiver instance.- Throws:
Exception- if the datagram socket couldn't be established.
-
-
Method Details
-
setDataReceiver
Set an instance which wants to get the received data.- Parameters:
dataReceiver-
-
run
public void run()Heart of the thread. It runs in an endless loop and provides the service continuously until the method "kill()" was invoked. When data is received, it is forwarded to the registered data recipient along with the IP address of the sender. -
kill
public void kill()Sets the killed-flag, closes the socket and performs an interrupt.
-