Class WritablePacket<T extends Client<Connection<T>>>


  • public abstract class WritablePacket<T extends Client<Connection<T>>>
    extends java.lang.Object
    This class represents a Packet that can be sent to clients. All data sent must have a header with 2 bytes and an optional payload. The first and second bytes is a 16 bits integer holding the size of the packet.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected WritablePacket()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canBeDropped​(T client)
      If this method returns true, the packet will be considered disposable.
      void sendInBroadcast​(boolean broadcast)
      Mark this packet as broadcast.
      java.lang.String toString()  
      protected abstract boolean write​(T client, WritableBuffer buffer)
      Writes the data to the client
      • Methods inherited from class java.lang.Object

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

      • WritablePacket

        protected WritablePacket()
    • Method Detail

      • sendInBroadcast

        public void sendInBroadcast​(boolean broadcast)
        Mark this packet as broadcast. A broadcast packet is sent to more than one client. Caution: This method should be called before Client.writePacket(WritablePacket) A broadcast packet will create a Buffer cache where the data is written once and only the copy is sent to the client. note: Each copy will be encrypted to each client
        Parameters:
        broadcast - true if the packet is sent to more than one client
      • canBeDropped

        public boolean canBeDropped​(T client)
        If this method returns true, the packet will be considered disposable.
        Parameters:
        client - client to send data to
        Returns:
        if the packet is disposable or not.
      • write

        protected abstract boolean write​(T client,
                                         WritableBuffer buffer)
        Writes the data to the client
        Parameters:
        client - client to send data
        buffer - where the data is written into
        Returns:
        the packet was written successful
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object