|
|||||||||
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.ServerSocketThread
public class ServerSocketThread
Nested Class Summary | |
---|---|
class |
ServerSocketThread.ServerSessionThread
ServerSessionThread |
static interface |
ServerSocketThread.SessionInfo
SessionInfo |
static class |
ServerSocketThread.SSEndOfStreamException
SSEndOfStreamException |
static class |
ServerSocketThread.SSReadTimeoutException
SSReadTimeoutException |
static class |
ServerSocketThread.SSSessionTimeoutException
SSSessionTimeoutException |
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
static boolean |
ACK_FROM_LISTEN_PORT
|
static int |
MinimumTimeoutIntervalMS
|
static int |
PACKET_LEN_END_OF_STREAM
|
static int |
PACKET_LEN_INCREMENT_EOL
|
static int |
PACKET_LEN_INCREMENTAL_
|
static int |
PACKET_LEN_INCREMENTAL_MASK
|
static int |
PACKET_LEN_LINE_TERMINATOR
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
ServerSocketThread(java.net.DatagramSocket ds)
Constructor for UDP connections |
|
ServerSocketThread(java.net.InetAddress bindAddr,
int port)
Constructor for TCP connections |
|
ServerSocketThread(java.net.InetAddress bindAddr,
int port,
boolean useSSL)
Constructor for TCP connections |
|
ServerSocketThread(int port)
Constructor for TCP connections |
|
ServerSocketThread(int port,
boolean useSSL)
Constructor for TCP connections |
|
ServerSocketThread(java.net.ServerSocket ss)
Constructor for TCP connections |
Method Summary | |
---|---|
void |
addActionListener(java.awt.event.ActionListener al)
Adds an action listener |
static java.net.DatagramSocket |
createDatagramSocket(java.net.InetAddress bindAddr,
int port)
Creates a DatagramSocket bound to the default local interface |
static java.net.ServerSocket |
createServerSocket(java.net.InetAddress bindAddr,
int port)
Creates a ServerSocket bound to the default local interface |
int[] |
getBackspaceChar()
Gets the backspace characters |
java.net.InetAddress |
getBindAddress()
Gets the local bind address |
ClientPacketHandler |
getClientPacketHandler()
Gets the current client packet handler |
java.net.DatagramSocket |
getDatagramSocket()
Gets the bound UDP DatagramSocket for this server handler. |
static java.net.InetAddress |
getDefaultBindAddress()
Gets the local bind address for all created ServerSocket's, or null if no specific bind address has been set |
long |
getIdleTimeout()
Gets the idle timeout in milliseconds |
int[] |
getIgnoreChar()
Gets the characters to ignore |
boolean |
getIncludePacketLineTerminator()
Returns True if the line terminator character should be included in the returned packet |
int[] |
getLineTerminatorChar()
Gets the line terminator characters |
int |
getLingerTimeoutSec()
Gets the linger timeout in seconds |
int |
getLocalPort()
Gets the local port to which this socket is bound |
boolean |
getLoggingEnabled()
Gets the logging enabled flag. |
int |
getMaximumClientThreadPoolSize()
Gets the maximum client thread pool size |
int |
getMaximumPacketLength()
Gets the maximum packet length |
int |
getMinimumPacketLength()
Gets the minimum packet length |
static java.net.InetAddress[] |
getNetworkInterfaceAddresses()
Returns an array of all local network interface addresses (excluding loopback) |
byte[] |
getPacketTerminatorPattern()
Returns the packet terminator pattern |
long |
getPacketTimeout()
Gets the packet timeout in milliseconds |
protected byte[] |
getPrompt(int ndx)
Gets the prompt for a specified index |
boolean |
getPromptEnabled()
Gets the prompt enabled state |
protected int |
getPromptIndex()
Gets the current prompt index (used for auto prompt) |
int |
getRemotePort()
Gets the remote UDP response port |
java.net.ServerSocket |
getServerSocket()
Gets the bound TCP ServerSocket for this server handler. |
long |
getSessionTimeout()
Gets the session timeout in milliseconds |
boolean |
getTerminateOnTimeout()
Gets if the thread should be terminated after a timeout [CHECK] |
static boolean |
hasBindAddress()
Returns true if a local bind address has been defined, otherwise false |
boolean |
hasListeners()
Returns true if this object has action listeners |
boolean |
hasPrompt()
If this server has a valid prompt |
boolean |
hasSessionTimeout()
Returns true if the session timeout has been defined |
boolean |
includePacketLineTerminator()
Returns True if the line terminator character should be included in the returned packet |
protected boolean |
invokeListeners(byte[] msgBytes)
Invokes action listener with the specified message |
boolean |
isBackspaceChar(int ch)
Returns true if ch is a backspace character |
boolean |
isIgnoreChar(int ch)
Returns true if ch is a character to ignore |
boolean |
isLineTerminatorChar(int ch)
Returns true if ch is a line terminator |
static boolean |
isLocalInterfaceAddress(java.net.InetAddress addr)
Returns true if the specified InetAddress is a local bound interface (including loopback) |
boolean |
isTextPackets()
Returns true if the packets are text |
static boolean |
isValidPort(int port)
Returns true if the specified port is valid |
boolean |
logActiveSessions(java.lang.String header)
Displays the active session list to the current log file (using "Print.logInfo") |
boolean |
logActiveSessions(java.lang.String header,
java.lang.StringBuffer asb)
Displays the active session list |
static void |
main(java.lang.String[] argv)
|
void |
removeActionListener(java.awt.event.ActionListener al)
Removes an action listener |
void |
run()
Listens for incoming connections and dispatches them to a handler thread |
boolean |
runInputStreamSession(java.io.InputStream dataInput,
boolean isDuplex,
boolean waitUntilDone)
Run a test session from the specified input stream |
static void |
sendDatagram(java.net.InetAddress bind,
java.net.InetAddress host,
int port,
byte[] data)
Sends a datagram to the specified host:port |
static void |
sendDatagram(java.net.InetAddress host,
int port,
byte[] data)
Sends a datagram to the specified host:port |
void |
setAutoPrompt(boolean auto)
If a default automatically generated prompt should be used [CHECK](all prompt related below) |
void |
setBackspaceChar(int bs)
Sets the backspace character |
void |
setBackspaceChar(int[] bs)
Sets the backspace characters |
static void |
setBindAddress(java.net.InetAddress bindAddr)
Sets the local bind address for all created ServerSocket's |
void |
setClientPacketHandler(ClientPacketHandler cph)
Sets the client packet handler [CHECK] |
void |
setClientPacketHandlerClass(java.lang.Class<? extends ClientPacketHandler> cphc)
Sets the client packet handler class [CHECK] |
void |
setIdleTimeout(long timeoutMS)
Sets the idle timeout in milliseconds |
void |
setIgnoreChar(int[] bs)
Sets the characters to ignore |
void |
setIncludePacketLineTerminator(boolean rtnTerm)
Sets whether the line terminator character should be included in the returned packets |
void |
setLineTerminatorChar(int term)
Sets the line terminator character |
void |
setLineTerminatorChar(int[] term)
Sets the line terminator characters |
void |
setLingerTimeoutSec(int timeoutSec)
Sets the linger timeout in seconds |
static void |
setListenBacklog(int backlog)
Sets the listen backlog for all created ServerSocket's |
void |
setLoggingEnabled(boolean enable)
Sets the logging enabled flag. |
void |
setMaximumClientThreadPoolSize(int maxSize)
Sets the maximum client thread pool size |
void |
setMaximumPacketLength(int len)
Sets the maximum packet length |
void |
setMinimumPacketLength(int len)
Sets the minimum packet length |
static void |
setMinimuTimeoutIntervalMS(int minTMS)
Sets the minimum timeout interval used for calling the ClientPacketHandler method " idleTimeoutInterrupt() ". |
void |
setPacketTerminatorPattern(byte[] pktTerm)
Sets the packet terminator pattern |
void |
setPacketTimeout(long timeoutMS)
Sets the packet timeout in milliseconds |
void |
setPrompt(byte[] prompt)
Sets the prompt for TCP connections |
void |
setPrompt(java.lang.String prompt)
Sets the prompt for TCP connections |
void |
setPromptEnabled(boolean enable)
Sets the prompt enabled state |
void |
setRemotePort(int remotePort)
Sets the remote UDP response port |
void |
setSessionTimeout(long timeoutMS)
Sets the session timeout in milliseconds |
void |
setTerminateOnTimeout(boolean timeoutQuit)
Sets if the thread should be terminated after a timeout [CHECK] |
void |
setTextPackets(boolean isText)
Sets if the packets to be sent are text |
boolean |
shutdown(long tmoMS)
Shuts down the server |
static boolean |
shutdownAll(long tmoMS)
|
void |
start()
Starts main ServerSocketThread port listener thread |
void |
start(java.lang.String name)
Starts this thread handler |
boolean |
sysPrintActiveSessions(java.lang.String header)
Prints the active session list to stdout |
boolean |
tcpWriteToSessionID(java.lang.String sessionID,
byte[] data)
Find the named TCP session and write the specified bytes TCP output stream |
void |
testSession(byte[] data,
boolean isDuplex)
Run a test session from the specified input data array |
void |
testSession(java.io.InputStream dataInput,
boolean isDuplex)
Run a test session from the specified input stream |
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, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int PACKET_LEN_INCREMENTAL_
public static final int PACKET_LEN_INCREMENTAL_MASK
public static final int PACKET_LEN_LINE_TERMINATOR
public static final int PACKET_LEN_END_OF_STREAM
public static final int PACKET_LEN_INCREMENT_EOL
public static final boolean ACK_FROM_LISTEN_PORT
public static int MinimumTimeoutIntervalMS
Constructor Detail |
---|
public ServerSocketThread(java.net.DatagramSocket ds)
public ServerSocketThread(java.net.ServerSocket ss)
ss
- The ServerSocket containing the 'listen' port informationpublic ServerSocketThread(java.net.InetAddress bindAddr, int port) throws java.io.IOException
port
- The port on which to listen for incoming connections
java.io.IOException
public ServerSocketThread(int port) throws java.io.IOException
port
- The port on which to listen for incoming connections
java.io.IOException
public ServerSocketThread(java.net.InetAddress bindAddr, int port, boolean useSSL) throws java.io.IOException
port
- The port on which to listen for incoming connectionsuseSSL
- True to enable an SSL
java.io.IOException
public ServerSocketThread(int port, boolean useSSL) throws java.io.IOException
port
- The port on which to listen for incoming connectionsuseSSL
- True to enable an SSL
java.io.IOException
Method Detail |
---|
public static void setMinimuTimeoutIntervalMS(int minTMS)
idleTimeoutInterrupt()
".
minTMS
- The minimum timeout interval in milliseconds.public static void setListenBacklog(int backlog)
backlog
- The listen backlogpublic static void setBindAddress(java.net.InetAddress bindAddr)
bindAddr
- The local bind addresspublic static boolean hasBindAddress()
public static java.net.InetAddress getDefaultBindAddress()
public static java.net.InetAddress[] getNetworkInterfaceAddresses() throws java.net.SocketException
java.net.SocketException
public static boolean isLocalInterfaceAddress(java.net.InetAddress addr)
public static java.net.DatagramSocket createDatagramSocket(java.net.InetAddress bindAddr, int port) throws java.net.SocketException
java.net.SocketException
public static java.net.ServerSocket createServerSocket(java.net.InetAddress bindAddr, int port) throws java.io.IOException
java.io.IOException
public static boolean isValidPort(int port)
port
- The port to test
public static boolean shutdownAll(long tmoMS)
public void start()
start
in class java.lang.Thread
java.lang.OutOfMemoryError
- If unable to create new native thread.
java.lang.IllegalThreadStateException
- If thread has already been started.public void start(java.lang.String name)
name
- the name to assign to this threadpublic void setLoggingEnabled(boolean enable)
enable
- True to enable, false to deisable (default is enabled)public boolean getLoggingEnabled()
public void setMaximumClientThreadPoolSize(int maxSize)
maxSize
- The maximum number of allowed client handler threads.
<= 0 for unlimited.public int getMaximumClientThreadPoolSize()
public java.net.DatagramSocket getDatagramSocket()
public java.net.ServerSocket getServerSocket()
public int getLocalPort()
public java.net.InetAddress getBindAddress()
public void testSession(byte[] data, boolean isDuplex)
data
- The test input data arraypublic void testSession(java.io.InputStream dataInput, boolean isDuplex)
dataInput
- The test input streampublic boolean runInputStreamSession(java.io.InputStream dataInput, boolean isDuplex, boolean waitUntilDone)
dataInput
- The test input streamisDuplex
- True to mimic "isDuplex()" in the AbstractClientPacketHandlerwaitUntilDone
- True to wait until the parsing is completepublic void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public boolean shutdown(long tmoMS)
public void setRemotePort(int remotePort)
remotePort
- The remote UDP respose portpublic int getRemotePort()
public boolean hasListeners()
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 boolean invokeListeners(byte[] msgBytes) throws java.lang.Exception
msgBytes
- The message to invoke the listeners with as a byte array
java.lang.Exception
public void setClientPacketHandler(ClientPacketHandler cph)
cph
- The client packet handlerpublic void setClientPacketHandlerClass(java.lang.Class<? extends ClientPacketHandler> cphc)
cphc
- The client packet handler classpublic ClientPacketHandler getClientPacketHandler()
public void setSessionTimeout(long timeoutMS)
timeoutMS
- The session timeout in millisecondspublic long getSessionTimeout()
public boolean hasSessionTimeout()
public void setIdleTimeout(long timeoutMS)
timeoutMS
- The idle timeout in millisecondspublic long getIdleTimeout()
public void setPacketTimeout(long timeoutMS)
timeoutMS
- The packet timeout in millisecondspublic long getPacketTimeout()
public void setTerminateOnTimeout(boolean timeoutQuit)
timeoutQuit
- True if the thread should be terminated after a timeoutpublic boolean getTerminateOnTimeout()
public void setLingerTimeoutSec(int timeoutSec)
timeoutSec
- The linger timeout in secondspublic int getLingerTimeoutSec()
public void setTextPackets(boolean isText)
isText
- True if the packets are textpublic boolean isTextPackets()
public void setMaximumPacketLength(int len)
len
- The maximum packet lengthpublic int getMaximumPacketLength()
public void setMinimumPacketLength(int len)
len
- The minimum packet lengthpublic int getMinimumPacketLength()
public void setLineTerminatorChar(int term)
term
- The line terminator characterpublic void setLineTerminatorChar(int[] term)
term
- The line terminator characterspublic int[] getLineTerminatorChar()
public boolean isLineTerminatorChar(int ch)
ch
is a line terminator
ch
is a line terminatorpublic void setIncludePacketLineTerminator(boolean rtnTerm)
rtnTerm
- True to include the line terminator character in returned packetspublic boolean getIncludePacketLineTerminator()
public boolean includePacketLineTerminator()
public void setPacketTerminatorPattern(byte[] pktTerm)
pktTerm
- The packet terminator patternpublic byte[] getPacketTerminatorPattern()
public void setBackspaceChar(int bs)
bs
- The backspace characterpublic void setBackspaceChar(int[] bs)
bs
- The backspace characterspublic int[] getBackspaceChar()
public boolean isBackspaceChar(int ch)
ch
is a backspace character
ch
is a backspace characterpublic void setIgnoreChar(int[] bs)
bs
- The characters to ignorepublic int[] getIgnoreChar()
public boolean isIgnoreChar(int ch)
ch
is a character to ignore
ch
is a character to ignorepublic void setAutoPrompt(boolean auto)
auto
- Ture if default automatic prompt should be usedpublic void setPrompt(byte[] prompt)
prompt
- The promptpublic void setPrompt(java.lang.String prompt)
prompt
- The promptprotected byte[] getPrompt(int ndx)
ndx
- The index (used for auto prompt)public boolean hasPrompt()
public void setPromptEnabled(boolean enable)
enable
- True to enable prompt, false to disablepublic boolean getPromptEnabled()
protected int getPromptIndex()
public boolean tcpWriteToSessionID(java.lang.String sessionID, byte[] data)
sessionID
- The session IDdata
- The bytes to write
public boolean logActiveSessions(java.lang.String header, java.lang.StringBuffer asb)
header
- The header to include on the listasb
- If non-null, writes the active session list to this StringBuffer.
Otherwise to the current log file (using "Print.logInfo").
public boolean logActiveSessions(java.lang.String header)
header
- The header to include on the list
public boolean sysPrintActiveSessions(java.lang.String header)
header
- The header to include on the list
public static void sendDatagram(java.net.InetAddress host, int port, byte[] data) throws java.io.IOException
host
- The destination hostport
- The destination portdata
- The data to send
java.io.IOException
- if an IO error occurspublic static void sendDatagram(java.net.InetAddress bind, java.net.InetAddress host, int port, byte[] data) throws java.io.IOException
bind
- The local bind addresshost
- The destination hostport
- The destination portdata
- The data to send
java.io.IOException
- if an IO error occurspublic static void main(java.lang.String[] argv)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |