Class CommunicationHandler


  • public class CommunicationHandler
    extends java.lang.Object
    Manages the Communication with a client by handling its IO.
    • Constructor Summary

      Constructors 
      Constructor Description
      CommunicationHandler​(java.net.Socket clientSocket, ClientManager clientManager)
      Creates a CommunicationHandler object for a socket
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the IOStreams and the socket itself.
      void flushRead()
      Forces the currently read bytes to be handled
      java.lang.String getIP()  
      protected void processReceivedData​(byte[] data)
      Gets called by the IOHandler when data is received from the client.
      void readNBytes​(int amount)
      Blocks until the given amount of bytes are read
      void registerListener​(IOHandlerListener listener)
      Registers a listener to the underlying IOHandler
      void registerListener​(java.util.ArrayList<IOHandlerListener> listener)
      Registers a list of listeners to the underlying IOHandler
      protected void send​(byte[] data)
      Sends data to the client
      • Methods inherited from class java.lang.Object

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

      • CommunicationHandler

        public CommunicationHandler​(java.net.Socket clientSocket,
                                    ClientManager clientManager)
        Creates a CommunicationHandler object for a socket
        Parameters:
        clientSocket - which IO should be handled
        clientManager - the clientManager of the server which accepted the client
    • Method Detail

      • close

        public void close()
        Closes the IOStreams and the socket itself.
      • send

        protected void send​(byte[] data)
        Sends data to the client
        Parameters:
        data - to send
      • flushRead

        public void flushRead()
        Forces the currently read bytes to be handled
      • readNBytes

        public void readNBytes​(int amount)
        Blocks until the given amount of bytes are read
        Parameters:
        amount - of bytes to read
      • processReceivedData

        protected void processReceivedData​(byte[] data)
        Gets called by the IOHandler when data is received from the client. It lets the DataPreProcessor process the data and then forwards the data to the server.
        Parameters:
        data - received from the client
      • registerListener

        public void registerListener​(IOHandlerListener listener)
        Registers a listener to the underlying IOHandler
        Parameters:
        listener - to add
      • registerListener

        public void registerListener​(java.util.ArrayList<IOHandlerListener> listener)
        Registers a list of listeners to the underlying IOHandler
        Parameters:
        listener - to add
      • getIP

        public java.lang.String getIP()
        Returns:
        the remote socket address of the associated client socket