- 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.voidflushRead()Forces the currently read bytes to be handledjava.lang.StringgetIP()protected voidprocessReceivedData(byte[] data)Gets called by the IOHandler when data is received from the client.voidreadNBytes(int amount)Blocks until the given amount of bytes are readvoidregisterListener(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
-
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 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
-
getIP
public java.lang.String getIP()
- Returns:
- the remote socket address of the associated client socket
-
-