class TcpSocketWriter
extends java.lang.Object
implements java.lang.Runnable
| Modifier and Type | Field and Description |
|---|---|
private boolean |
keepAlive
When set to false, if this thread is interrupted, it will die.
|
private TcpClient |
tcpClient
The TcpClient which instantiated this class.
|
private java.io.PrintWriter |
tcpSocketWriter
PrintWriter instance which is tied to the socket's output stream.
|
| Constructor and Description |
|---|
TcpSocketWriter(java.net.Socket socketToWriteTo,
TcpClient tcpClient)
Constructs a new TcpSocketWriter.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
logMsg(java.lang.String msg)
Logs/outputs a message.
|
(package private) void |
requestStop()
Sets the keepAlive flag to false.
|
void |
run()
The function called when this class is executed as a thread.
|
private void |
write(Message msg)
Writes the message specified by the parameter, followed by a newline to the
server.
|
private boolean keepAlive
private final java.io.PrintWriter tcpSocketWriter
private final TcpClient tcpClient
TcpSocketWriter(java.net.Socket socketToWriteTo,
TcpClient tcpClient)
throws java.io.IOException
socketToWriteTo - The socket which is connected to the server, which this thread
will write to.tcpClient - The TcpClient which instantiated this classjava.io.IOException - In the event that there was an error retrieving the output stream
of the socket parampublic void run()
run in interface java.lang.Runnableprivate void write(Message msg)
private void logMsg(java.lang.String msg)
msg - The msg to logvoid requestStop()