Class UdpReceiver

java.lang.Object
java.lang.Thread
de.das.encrypter.comm.UdpReceiver
All Implemented Interfaces:
Runnable

public class UdpReceiver extends Thread
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.
  • Constructor Details

    • UdpReceiver

      public UdpReceiver(int port, DataReceiver recv) throws Exception
      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

      public UdpReceiver(String name, int port, DataReceiver recv) throws Exception
      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

      public void setDataReceiver(DataReceiver dataReceiver)
      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.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • kill

      public void kill()
      Sets the killed-flag, closes the socket and performs an interrupt.