- java.lang.Object
-
- dev.bitbite.networking.CommunicationHandler
-
public class CommunicationHandler extends java.lang.ObjectManages 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 voidclose()Closes the IOStreams and the socket itself.IOHandlergetIOHandler()Returns the IOHandler associated with this communicationHandlerjava.lang.StringgetIP()protected voidprocessReceivedData(byte[] data)Gets called by the IOHandler when data is received from the client.voidregisterListener(IOHandlerListener listener)Registers a listener to the underlying IOHandlervoidregisterListener(java.util.ArrayList<IOHandlerListener> listener)Registers a list of listeners to the underlying IOHandlerprotected voidsend(byte[] data)Sends data to the client
-
-
-
Constructor Detail
-
CommunicationHandler
public CommunicationHandler(java.net.Socket clientSocket, ClientManager clientManager)Creates a CommunicationHandler object for a socket- Parameters:
clientSocket- which IO should be handledclientManager- 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
-
processReceivedData
protected void processReceivedData(byte[] data)
Gets called by the IOHandler when data is received from the client. It lets theDataPreProcessorprocess 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
-
getIOHandler
public IOHandler getIOHandler()
Returns the IOHandler associated with this communicationHandler- Returns:
- the IOHandler associated with this communicationHandler
-
getIP
public java.lang.String getIP()
- Returns:
- the remote socket address of the associated client socket
-
-