|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread org.opengts.util.ClientSocketThread
public class ClientSocketThread
Threaded messaging socket client
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary |
---|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
ClientSocketThread(java.lang.String host,
int port)
Constructor |
|
ClientSocketThread(java.lang.String host,
int port,
boolean useSSL)
Constructor |
Method Summary | |
---|---|
void |
addActionListener(java.awt.event.ActionListener al)
Adds an action listener |
void |
closeSocket()
Closes the socket connection |
static java.lang.String |
getLineTerminator()
Returns the line terminator character (as a String value) for "socketWriteLine" |
static char |
getLineTerminatorChar()
Returns the line terminator character for "socketWriteLine" |
long |
getReadTimeout()
Gets the read timeout in milliseconds |
protected void |
handleMessage(java.lang.String msg)
Invokes all listeners with an assciated command. |
protected void |
invokeListeners(java.lang.String r)
Invokes all listeners with an assciated command |
boolean |
isRunning()
Returns true if the thread is currently running |
static void |
main(java.lang.String[] argv)
Main entry point for testing/debugging |
void |
openSocket()
Opens the socket connection |
void |
openSocket(long timeoutMS)
Opens the socket connection |
void |
removeActionListener(java.awt.event.ActionListener al)
Removes an action listener |
void |
run()
Main client thread loop |
void |
sendMessage(java.lang.String msg)
Queues a message to be sent |
static void |
setLineTerminatorChar(char lt)
Sets the line terminator character for "socketWriteLine" |
void |
setReadTimeout(long ms)
Sets the read timeout in milliseconds |
boolean |
setSocketReadTimeout()
Sets the read timeout on the currently open socket to the previous specified value |
boolean |
setSocketReadTimeout(long ms)
Sets the read timeout on the currently open socket to the specified value |
int |
socketReadBytes(java.io.ByteArrayOutputStream baos,
int maxLength)
Reads the bytes from the specifed socket until an eod-of-stream error occurs, or until the maximum number of bytes has bee read. |
byte[] |
socketReadBytes(int length)
Reads the specified number of bytes from the socket |
protected static int |
socketReadBytes(java.net.Socket socket,
java.io.ByteArrayOutputStream baos,
int maxLength)
Reads the bytes from the specifed socket until an eod-of-stream error occurs, or until the maximum number of bytes has bee read. |
protected static byte[] |
socketReadBytes(java.net.Socket socket,
int length)
Reads the specified number of bytes from the specifed socket |
java.lang.String |
socketReadLine()
Reads a line from the socket input stream |
java.lang.String |
socketReadLine(int maxLen)
Reads a line from the socket input stream |
java.lang.String |
socketReadLine(int maxLen,
java.lang.StringBuffer sb)
Reads a line from the socket input stream |
protected static java.lang.String |
socketReadLine(java.net.Socket socket,
int maxLen,
java.lang.StringBuffer sb)
Reads a line from the specified socket's input stream |
java.lang.String |
socketReadLine(java.lang.StringBuffer sb)
Reads a line from the socket input strea |
void |
socketWriteBytes(byte[] b)
Writes the specified byte array to the socket output stream |
void |
socketWriteBytes(byte[] b,
int offset,
int length)
Writes length bytes from the specified byte array
starting at offset to the socket output stream. |
protected static void |
socketWriteBytes(java.net.Socket socket,
byte[] b)
Writes the specified byte array to the specified socket's output stream |
protected static void |
socketWriteBytes(java.net.Socket socket,
byte[] b,
int offset,
int length)
Writes length bytes from the specified byte array
starting at offset to the specified socket's output stream. |
protected static void |
socketWriteLine(java.net.Socket socket,
java.lang.String val)
Writes the specified line to the specified socket's output stream |
void |
socketWriteLine(java.lang.String val)
Writes the specified line to the socket output stream |
protected static void |
socketWriteString(java.net.Socket socket,
java.lang.String val)
Writes the specified String to the specified socket's output stream |
protected static void |
socketWriteString(java.net.Socket socket,
java.lang.StringBuffer val)
Writes the specified StringBuffer to the specified socket's output stream |
void |
socketWriteString(java.lang.String val)
Writes the specified String to the socket output stream |
void |
socketWriteString(java.lang.StringBuffer val)
Writes the specified StringBuffer to the socket output stream |
void |
startThread()
Causes this thread to begin execution |
void |
stopThread()
Attemps to stop the thread [CHECK] |
protected void |
threadStarted()
Called when the thread is started |
protected void |
threadStopped()
Called when the thread has stopped |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ClientSocketThread(java.lang.String host, int port)
host
- The host name to connect toport
- The port number to usepublic ClientSocketThread(java.lang.String host, int port, boolean useSSL)
host
- The host name to connect toport
- The port number to useuseSSL
- True if SSL is to be usedMethod Detail |
---|
public long getReadTimeout()
public void setReadTimeout(long ms)
ms
- The read timeout in millisecondspublic boolean setSocketReadTimeout() throws java.net.SocketException
java.net.SocketException
public boolean setSocketReadTimeout(long ms) throws java.net.SocketException
java.net.SocketException
public void openSocket() throws java.io.IOException
java.io.IOException
- if an error occurs while creating the socketpublic void openSocket(long timeoutMS) throws java.io.IOException
timeoutMS
- open timeout in milliseconds
java.io.IOException
- if an error occurs while creating the socketpublic void closeSocket()
public void socketWriteBytes(byte[] b) throws java.io.IOException
b
- The byte array to write to the socket output stream
java.io.IOException
- if an error occurspublic void socketWriteBytes(byte[] b, int offset, int length) throws java.io.IOException
length
bytes from the specified byte array
starting at offset
to the socket output stream.
b
- The byte array to write to the socket output streamoffset
- The start offset in the data to begin writing atlength
- The length of the data. Normally b.length
java.io.IOException
- if an error occursprotected static void socketWriteBytes(java.net.Socket socket, byte[] b, int offset, int length) throws java.io.IOException
length
bytes from the specified byte array
starting at offset
to the specified socket's output stream.
socket
- The socket which's output stream to write tob
- The byte array to write to the socket output streamoffset
- The start offset in the data to begin writing atlength
- The length of the data. Normally b.length
java.io.IOException
- if an error occursprotected static void socketWriteBytes(java.net.Socket socket, byte[] b) throws java.io.IOException
socket
- The socket which's output stream to write tob
- The byte array to write to the socket output stream
java.io.IOException
- if an error occurspublic void socketWriteString(java.lang.StringBuffer val) throws java.io.IOException
val
- The StringBuffer to write to the socket output stream.
java.io.IOException
- if an error occursprotected static void socketWriteString(java.net.Socket socket, java.lang.StringBuffer val) throws java.io.IOException
socket
- The socket which's output stream to write toval
- The StringBuffer to write to the socket output stream.
java.io.IOException
- if an error occurspublic void socketWriteString(java.lang.String val) throws java.io.IOException
val
- The String to write to the socket output stream.
java.io.IOException
- if an error occursprotected static void socketWriteString(java.net.Socket socket, java.lang.String val) throws java.io.IOException
socket
- The socket which's output stream to write toval
- The String to write to the socket output stream.
java.io.IOException
- if an error occurspublic void socketWriteLine(java.lang.String val) throws java.io.IOException
val
- The line to write to the socket output stream. A newline is
appended if it does not already end with one.
java.io.IOException
- if an error occursprotected static void socketWriteLine(java.net.Socket socket, java.lang.String val) throws java.io.IOException
socket
- The socket which's output stream to write toval
- The line to write to the socket output stream. A newline is
appended if it does not already end with one.
java.io.IOException
- if an error occurspublic static java.lang.String getLineTerminator()
public static char getLineTerminatorChar()
public static void setLineTerminatorChar(char lt)
lt
- The line terminator characterpublic byte[] socketReadBytes(int length) throws java.io.IOException
length
- The number of bytes to read from the socket
java.io.IOException
- if an error occured or the server has stoppedprotected static byte[] socketReadBytes(java.net.Socket socket, int length) throws java.io.IOException
socket
- The socket from which bytes are readlength
- The number of bytes to read from the socket
java.io.IOException
- if an error occured or the server has stoppedpublic int socketReadBytes(java.io.ByteArrayOutputStream baos, int maxLength) throws java.io.IOException
baos
- The ByteArrayOutputStream to which the bytes are writtenmaxLength
- The number of bytes to read from the socket
java.io.IOException
- if an error occured or the server has stopped. ByteArrayOutputStream
will still contain all bytes read from the stream up until it failed.protected static int socketReadBytes(java.net.Socket socket, java.io.ByteArrayOutputStream baos, int maxLength) throws java.io.IOException
socket
- The socket from which bytes are readbaos
- The ByteArrayOutputStream to which the bytes are writtenmaxLength
- The number of bytes to read from the socket
java.io.IOException
- if an error occured or the server has stoppedpublic java.lang.String socketReadLine() throws java.io.IOException
java.io.IOException
- if an error occurs or the server has stoppedpublic java.lang.String socketReadLine(int maxLen) throws java.io.IOException
maxLen
- The maximum length of the line to read
java.io.IOException
- if an error occurs or the server has stoppedpublic java.lang.String socketReadLine(java.lang.StringBuffer sb) throws java.io.IOException
sb
- The string buffer to use
java.io.IOException
- if an error occurs or the server has stoppedpublic java.lang.String socketReadLine(int maxLen, java.lang.StringBuffer sb) throws java.io.IOException
maxLen
- The maximum length of of the line to readsb
- The string buffer to use
java.io.IOException
- if an error occurs or the server has stoppedprotected static java.lang.String socketReadLine(java.net.Socket socket, int maxLen, java.lang.StringBuffer sb) throws java.io.IOException
socket
- The socket to read a line frommaxLen
- The maximum length of of the line to readsb
- The string buffer to use
java.io.IOException
- if an error occurs or the server has stoppedpublic void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
protected void threadStarted()
protected void threadStopped()
public void stopThread()
public void startThread()
public boolean isRunning()
public void sendMessage(java.lang.String msg)
public void addActionListener(java.awt.event.ActionListener al)
al
- The action listener to addpublic void removeActionListener(java.awt.event.ActionListener al)
al
- The action listener to removeprotected void invokeListeners(java.lang.String r)
r
- a string that may specify a command (possibly one
of several) associated with the eventprotected void handleMessage(java.lang.String msg)
msg
- a string that may specify a command (possibly one
of several) associated with the eventinvokeListeners(java.lang.String)
public static void main(java.lang.String[] argv)
argv
- Comand-line arguments
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |