Class ClientHandler
java.lang.Object
java.lang.Thread
fr.r1r0r0.deltaengine.model.engines.network.server.ClientHandler
- All Implemented Interfaces:
java.lang.Runnable
final class ClientHandler
extends java.lang.Thread
Client handler for a Server. Represents an unique client connected.
Contains its own buffer, who will receive all data from the client machine,
when its run() method is called.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
-
Field Summary
Fields Modifier and Type Field Description private java.util.Collection<java.lang.Object>
buffer
private java.net.Socket
client
private java.io.ObjectInputStream
inputStream
private java.io.ObjectOutputStream
outputStream
private Server
server
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
Constructors Constructor Description ClientHandler(Server server, java.net.Socket client)
Default constructor. -
Method Summary
Modifier and Type Method Description void
close()
End client connectionprivate void
initBuffer()
Initializes internal bufferboolean
isClosed()
Check if connection has been closedjava.util.Collection<java.lang.Object>
receive()
Retrieve all data received from the client and reset its buffervoid
run()
void
send(java.lang.Object... objects)
Send data to bound clientMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
server
-
client
private final java.net.Socket client -
outputStream
private final java.io.ObjectOutputStream outputStream -
inputStream
private final java.io.ObjectInputStream inputStream -
buffer
private java.util.Collection<java.lang.Object> buffer
-
-
Constructor Details
-
ClientHandler
Default constructor. Creates a client handler for the server.- Parameters:
server
- the serverclient
- client socket- Throws:
java.io.IOException
- when socket exception occurs
-
-
Method Details
-
run
public void run()- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
send
public void send(java.lang.Object... objects) throws java.io.IOExceptionSend data to bound client- Parameters:
objects
- objects to send- Throws:
java.io.IOException
- default exceptions thrown by Java libraries
-
receive
public java.util.Collection<java.lang.Object> receive()Retrieve all data received from the client and reset its buffer- Returns:
- Collection of objects received
-
close
public void close()End client connection -
isClosed
public boolean isClosed()Check if connection has been closed- Returns:
- boolean, true if connection is closed, false otherwise
-
initBuffer
private void initBuffer()Initializes internal buffer
-