Class KeepAlivePacket

    • Constructor Summary

      Constructors 
      Constructor Description
      KeepAlivePacket()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      short getId()  
      void handle​(java.io.DataInputStream in)
      Called by the DataReader when a packet with this id is read.
      boolean isCritical()
      Defines whether this packet type is critical.
      Critical means that the handle() function should never fail.
      boolean isResponse()  
      PacketWriter prepare()
      Called by the DataSender when this packet is send over the network.
      void setResponse​(boolean response)  
      • Methods inherited from class java.lang.Object

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

      • KeepAlivePacket

        public KeepAlivePacket()
    • Method Detail

      • getId

        public short getId()
        Specified by:
        getId in class Packet
        Returns:
        The id of this packet. Should always return the same value. Note: Please use only positive numbers
      • handle

        public void handle​(java.io.DataInputStream in)
                    throws java.io.IOException
        Description copied from class: Packet
        Called by the DataReader when a packet with this id is read. This method/function should read data and store the values in his own attributes.

        Example:
        this.message = in.readUTF();

        This method is connected with the prepare() function. All data that is written in the prepare() function should be read in this method in the same order.
        Specified by:
        handle in class Packet
        Parameters:
        in - A DataInputStream, provided by the DataReader containing all the data (if nothing failed) that is needed to handle this packet.
        The DataInputStream has a fixed length so you can't read more bytes than in.available() to avoid issues with other packets. If in has not enough bytes to fill this packet with data, simply throw an IOException. The DataInputStream will also throw a EOFException when you try to read more bytes than in.available()
        Throws:
        java.io.IOException - If reading fails, e.g there are not enough bytes or the bytes are wrong encoded (e.g you want to read UTF but there is no UTF-String encoded in bytes)
        See Also:
        Packet.prepare()
      • prepare

        public PacketWriter prepare()
                             throws java.io.IOException
        Description copied from class: Packet
        Called by the DataSender when this packet is send over the network. This method/function should write data that is stored in his own attributes into a PacketWriter. You have to create a new PacketWriter instance for that.

        Example:
        PacketWriter writer = new PacketWriter(getId());
        writer.writeUTF(this.message);
        return writer;


        This method is connected with the handle() function. All data that is read in the handle() function should be written in this method in the same order.
        Specified by:
        prepare in class Packet
        Returns:
        A new PacketWriter instance where all the data of this packet is stored
        Throws:
        java.io.IOException - If a PacketWriter call fails. Should never happen (since the PacketWriter only stores data in the memory)
        See Also:
        Packet.handle(DataInputStream)
      • isCritical

        public boolean isCritical()
        Description copied from class: Packet
        Defines whether this packet type is critical.
        Critical means that the handle() function should never fail. If it fails though the connection will be terminated
        Note: If a prepare() call fails the connection is also terminated (and marked as failed) no matter if the packet is critical or not
        Specified by:
        isCritical in class Packet
        Returns:
        Whether this packet type is a critical packet that has to be received properly or not.
      • isResponse

        public boolean isResponse()
      • setResponse

        public void setResponse​(boolean response)