Class Client<T extends Connection<?>>


  • public abstract class Client<T extends Connection<?>>
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Client​(T connection)
      Construct a new Client
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close​(WritablePacket<? extends Client<T>> packet)
      Sends the packet and close the underlying Connection to the client.
      abstract boolean decrypt​(byte[] data, int offset, int size)
      Decrypt the data in-place
      protected void disconnect()  
      abstract int encrypt​(byte[] data, int offset, int size)
      Encrypt the data in-place.
      java.lang.String getHostAddress()  
      protected boolean isConnected()  
      abstract void onConnected()
      Handles the client's connection.
      protected abstract void onDisconnection()
      Handles the client's disconnection.
      protected void writePacket​(WritablePacket<? extends Client<T>> packet)
      Sends a packet to this client.
      • Methods inherited from class java.lang.Object

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

      • Client

        public Client​(T connection)
        Construct a new Client
        Parameters:
        connection - - The Connection to the client.
        Throws:
        java.lang.IllegalArgumentException - if the connection is null or closed.
    • Method Detail

      • writePacket

        protected void writePacket​(WritablePacket<? extends Client<T>> packet)
        Sends a packet to this client. If another packet is been sent to this client, the actual packet is put on a queue to be sent after all previous packets. Otherwise the packet is sent immediately.
        Parameters:
        packet - to be sent.
      • close

        public void close​(WritablePacket<? extends Client<T>> packet)
        Sends the packet and close the underlying Connection to the client. All others pending packets are cancelled.
        Parameters:
        packet - to be sent before the connection is closed.
      • disconnect

        protected final void disconnect()
      • getHostAddress

        public java.lang.String getHostAddress()
        Returns:
        The client's IP address.
      • isConnected

        protected boolean isConnected()
      • encrypt

        public abstract int encrypt​(byte[] data,
                                    int offset,
                                    int size)
        Encrypt the data in-place.
        Parameters:
        data - - the data to be encrypted
        offset - - the initial index to be encrypted
        size - - the length of data to be encrypted
        Returns:
        The data size after encrypted
      • decrypt

        public abstract boolean decrypt​(byte[] data,
                                        int offset,
                                        int size)
        Decrypt the data in-place
        Parameters:
        data - - data to be decrypted
        offset - - the initial index to be encrypted.
        size - - the length of data to be encrypted.
        Returns:
        if the data was decrypted.
      • onDisconnection

        protected abstract void onDisconnection()
        Handles the client's disconnection. This method must save all data and release all resources related to the client. No more packet can be sent after this method is called.
      • onConnected

        public abstract void onConnected()
        Handles the client's connection. The Packets can be sent only after this method is called.