java.lang.Object
java.lang.Thread
nl.andrewl.concord_server.client.ClientThread
- All Implemented Interfaces:
Runnable
This thread is responsible for handling the connection to a single client of
a server. The client thread acts as the server's representation of a client.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate UUID
private String
private Channel
private InputStream
private OutputStream
private boolean
private final ConcordServer
private final Socket
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionClientThread
(Socket socket, ConcordServer server) Constructs a new client thread. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
Tries to establish an encrypted connection with a client.private boolean
Initial method that attempts to obtain identification information from a newly-connected client.void
run()
void
sendToClient
(byte[] bytes) Sends the given bytes to the client.void
sendToClient
(nl.andrewl.concord_core.msg.Message message) Sends the given message to the client.void
shutdown()
Shuts down this client thread, closing the underlying socket and settingrunning
to false so that the main thread loop will exit shortly.nl.andrewl.concord_core.msg.types.UserData
toData()
toString()
Methods 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, yield
-
Field Details
-
socket
-
in
-
out
-
server
-
clientId
-
clientNickname
-
currentChannel
-
running
private volatile boolean running
-
-
Constructor Details
-
ClientThread
Constructs a new client thread.- Parameters:
socket
- The socket to use to communicate with the client.server
- The server to which this thread belongs.- Throws:
IOException
- If we cannot obtain the input and output streams from the socket.
-
-
Method Details
-
sendToClient
public void sendToClient(nl.andrewl.concord_core.msg.Message message) Sends the given message to the client. Note that this method is synchronized, such that multiple messages cannot be sent simultaneously.- Parameters:
message
- The message to send.
-
sendToClient
public void sendToClient(byte[] bytes) Sends the given bytes to the client. This is a shortcut forsendToClient(Message)
which can be used to optimize message sending in certain instances.- Parameters:
bytes
- The bytes to send.
-
shutdown
public void shutdown()Shuts down this client thread, closing the underlying socket and settingrunning
to false so that the main thread loop will exit shortly. -
run
public void run() -
identifyClient
private boolean identifyClient()Initial method that attempts to obtain identification information from a newly-connected client. It is the intent that we should close the socket if the client is not able to identify itself.- Returns:
- True if we were able to obtain identification from the client, or false otherwise.
-
establishEncryption
private boolean establishEncryption()Tries to establish an encrypted connection with a client. This should be the first thing which is called upon to interact with the client, because it assumes that the client is also attempting to establish a secure connection as soon as it opens its socket.- Returns:
- True if an encrypted connection could be established, or false otherwise.
-
toData
public nl.andrewl.concord_core.msg.types.UserData toData() -
toString
-