Class UdpSender

java.lang.Object
de.das.encrypter.comm.UdpSender

public class UdpSender extends Object
A simple UDP sender expecting a receiver service for a given host address at the given port, which is able to receive and interpret the data sent.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UdpSender(int port)
    Creates a new sender client instance and provides a datagram socket for connection and sending.
    UdpSender(String host, int port)
    Creates a new sender client instance and provides a datagram socket for connection and sending.
    UdpSender(String name, String host, int port)
    Creates a new sender client instance and provides a datagram socket for connection and sending.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    callServer(byte[] data)
    Tries to send the given byte array as a UDP message to the port of the predefined host.
    void
    callServer(String host, byte[] data)
    Tries to send the given byte array as a UDP message to the port of the given host.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UdpSender

      public UdpSender(int port) throws Exception
      Creates a new sender client instance and provides a datagram socket for connection and sending.
      Parameters:
      port - the port number where a service is expected at the host.
      Throws:
      Exception - if the datagram socket cannot be establisched.
    • UdpSender

      public UdpSender(String host, int port) throws Exception
      Creates a new sender client instance and provides a datagram socket for connection and sending.
      Parameters:
      host - a predefined host address for later usage.
      port - the port number where a service is expected at the host.
      Throws:
      Exception - if the datagram socket cannot be establisched.
    • UdpSender

      public UdpSender(String name, String host, int port) throws SocketException
      Creates a new sender client instance and provides a datagram socket for connection and sending.
      Parameters:
      name - of the sender.
      host - a predefined host address for later usage.
      port - the port number where a service is expected at the host.
      Throws:
      SocketException - if the datagram socket cannot be establisched.
  • Method Details

    • callServer

      public void callServer(byte[] data)
      Tries to send the given byte array as a UDP message to the port of the predefined host.
      Parameters:
      data - the byte array to be sent.
    • callServer

      public void callServer(String host, byte[] data)
      Tries to send the given byte array as a UDP message to the port of the given host.
      Parameters:
      host - the address of the receiver.
      data - the byte array to be sent.