Class DynamicAddressChannel

  • All Implemented Interfaces:
    Runnable, DatagramListener

    public class DynamicAddressChannel
    extends Object
    implements Runnable, DatagramListener
    Listen packets from defined dataSocket and send packets to the defined host. But also provides a mechanism to dynamic bind host and port implementing DatagramListener methods to change the host and port values according to the received packets.
    Author:
    Thiago Camargo
    • Constructor Detail

      • DynamicAddressChannel

        public DynamicAddressChannel​(DatagramSocket dataSocket,
                                     InetAddress host,
                                     int port)
        Default Channel Constructor
        Parameters:
        dataSocket - datasocket to used to send and receive packets
        host - default destination host for received packets
        port - default destination port for received packets
    • Method Detail

      • datagramReceived

        public boolean datagramReceived​(DatagramPacket datagramPacket)
        Implement DatagramListener method. Set the host and port value to the host and port value from the received packet.
        Specified by:
        datagramReceived in interface DatagramListener
        Parameters:
        datagramPacket - the received packet
        Returns:
        ?
      • getHost

        public InetAddress getHost()
        Get the host that the packet will be sent to.
        Returns:
        remote host address
      • setHost

        protected void setHost​(InetAddress host)
        Set the host that the packet will be sent to.
        Parameters:
        host - the host to send the packet to
      • getPort

        public int getPort()
        Get the port that the packet will be sent to.
        Returns:
        The remote port number
      • setPort

        protected void setPort​(int port)
        Set the port that the packet will be sent to.
        Parameters:
        port - the port to send the packet to
      • addListener

        public void addListener​(DatagramListener datagramListener)
        Adds a DatagramListener to the Channel
        Parameters:
        datagramListener - the listener to add
      • removeListener

        public void removeListener​(DatagramListener datagramListener)
        Remove a DatagramListener from the Channel
        Parameters:
        datagramListener - the listener to remove
      • removeListeners

        public void removeListeners()
        Remove every Listeners
      • cancel

        public void cancel()
      • run

        public void run()
        Thread override method
        Specified by:
        run in interface Runnable