|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--thegame.shared.GameConnection
Defines methods and data members used by GameClientConnection and GameServerConnection.
Field Summary | |
protected java.io.BufferedReader |
in
Used for reading from the socket. |
protected boolean |
isRunning
Is true if the thread is running; is false otherwise. |
protected java.io.PrintWriter |
out
Used for writing to the socket. |
protected java.net.Socket |
socket
The socket used. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
GameConnection(java.net.Socket socket)
Constructs a GameConnection on the specified socket. |
Method Summary | |
void |
close()
Closes the socket. |
static java.lang.String |
getMessageBody(java.lang.String message)
Returns the body of the message, or null if the message has no body. |
static int[] |
getMessageContentsAs1DIntArray(java.lang.String message)
Returns the contents of the message as int[2], or null if the message has no body. |
static java.lang.String[] |
getMessageContentsAs1DStringArray(java.lang.String message)
Returns the contents of the message as a String array, or null if the message has no body. |
static int[][] |
getMessageContentsAs2DIntArray(java.lang.String message)
Returns the contents of the message in the form of int[x][2] (where x is undefined), or null if the message has no body. |
static boolean |
getMessageContentsAsBoolean(java.lang.String message)
Returns the contents of the message as a boolean value. |
static int |
getMessageID(java.lang.String message)
Returns the type identifier of the message. |
static java.lang.String |
getReadyToSendForm(int id,
java.lang.String[] body)
Returns the method arguments in a form that is ready to be sent as a message. |
void |
send(int id)
Sends a message with id as the type identifier of the message. |
void |
send(int id,
boolean body)
Sends a message with id as the message type identifier and body as the body of the message. |
void |
send(int id,
int[] body)
Sends a message with id as the type identifier of the message and body as the body of the message. |
void |
send(int id,
int[][] body)
Sends a message with id as the type identifier of the message and body as the body of the message. |
void |
send(int id,
java.lang.String body)
Sends a message with id as the message type identifier and body as the body of the message. |
void |
send(java.lang.String str)
Sends a string. |
void |
setRunning(boolean running)
Sets the isRunning property. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.io.BufferedReader in
protected boolean isRunning
protected java.io.PrintWriter out
protected java.net.Socket socket
Constructor Detail |
public GameConnection(java.net.Socket socket) throws java.io.IOException
socket
- the socket used; must be already createdjava.io.IOException
- if an I/O error occurs when creating the I/O streamsMethod Detail |
public void close()
public static java.lang.String getMessageBody(java.lang.String message)
message
- the message to be parsedpublic static int[] getMessageContentsAs1DIntArray(java.lang.String message)
message
- the message to be parsedpublic static java.lang.String[] getMessageContentsAs1DStringArray(java.lang.String message)
message
- the message to be parsedpublic static int[][] getMessageContentsAs2DIntArray(java.lang.String message)
message
- the message to be parsedpublic static boolean getMessageContentsAsBoolean(java.lang.String message)
message
- the message to be parsedpublic static int getMessageID(java.lang.String message)
message
- the message to be parsedpublic static java.lang.String getReadyToSendForm(int id, java.lang.String[] body)
id
- the type identifier of the messagebody
- the body of the messagepublic void send(int id) throws java.io.IOException
id
- the type identifier of the messagejava.io.IOException
- if an I/O error occurspublic void send(int id, boolean body) throws java.io.IOException
id
- the type identifier of the messagebody
- the body of the messagejava.io.IOException
- if an I/O error occurspublic void send(int id, int[] body) throws java.io.IOException
id
- the type identifier of the messagebody
- the body of the messagejava.io.IOException
- if an I/O error occurspublic void send(int id, int[][] body) throws java.io.IOException
id
- the type identifier of the messagebody
- the body of the messagejava.io.IOException
- if an I/O error occurspublic void send(int id, java.lang.String body) throws java.io.IOException
id
- the type identifier of the messagebody
- the body of the messagejava.io.IOException
- if an I/O error occurspublic void send(java.lang.String str) throws java.io.IOException
str
- the data to be sentjava.io.IOException
- if an I/O error occurspublic void setRunning(boolean running)
running
- false if the GameConnection thread is to stop; true otherwise
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |