|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
com.amx.duet.tools.net.tcp.SocketConnection
This class is used to manage TCP/IP socket connections on a single thread making it safe for AMX masters.
Field Summary | |
static java.lang.String |
className
|
static int |
CLOSED
|
static int |
CONNECTED
|
static int |
FAILED_CONNECT
|
static int |
INFINITE
|
static int |
INVALID_HOST
|
static int |
TIMEOUT
|
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
SocketConnection(java.net.InetAddress addr,
int port,
int bufferSize,
SocketConnectionListener listener)
Creates a simple socket connection along with a receive thread for reading the socket. |
|
SocketConnection(java.net.InetAddress addr,
int port,
int bufferSize,
SocketConnectionListener listener,
int timeout)
Creates a simple socket along with a receive thread for reading the socket. |
|
SocketConnection(java.net.InetAddress addr,
int port,
int bufferSize,
SocketConnectionListener listener,
int timeout,
boolean TcpNoDelayOn)
Creates a simple socket along with a receive thread for reading the socket. |
|
SocketConnection(java.lang.String host,
int port,
int bufferSize,
SocketConnectionListener listener)
Creates a simple socket along with a receive thread for reading the socket. |
|
SocketConnection(java.lang.String host,
int port,
int bufferSize,
SocketConnectionListener listener,
int timeout)
Creates a simple socket along with a receive thread for reading the socket. |
|
SocketConnection(java.lang.String host,
int port,
int bufferSize,
SocketConnectionListener listener,
int timeout,
boolean TcpNoDelayOn)
Creates a simple socket along with a receive thread for reading the socket. |
Method Summary | |
boolean |
connect()
The first time connect is called for a SocketConnection, the receive thread is started and a socket object is created connected to the address and port. |
void |
disconnect()
Closes the socket. |
void |
dispose()
Destroys the socket connection and terminates the receive thread. |
void |
finalize()
|
void |
flushQueue(boolean send)
Flushes any message awaiting send by either sending them to the SocketConnection's output stream or discarding the message based on the send argument. |
int |
getDebugState()
Gets the current diagnostic state. |
void |
initConnection(java.lang.String addrStr,
int port,
int bufferSize,
SocketConnectionListener listener,
int timeout)
|
void |
initConnection(java.lang.String addrStr,
int port,
int bufferSize,
SocketConnectionListener listener,
int timeout,
boolean TcpNoDelayOn)
|
boolean |
isConnected()
|
void |
log(int level,
java.lang.String msg)
|
void |
run()
|
boolean |
setAddressAndPort(java.net.InetAddress addr,
int port)
Sets the socket connections IP address and port to the specified values. |
boolean |
setAddressAndPort(java.lang.String host,
int port)
Sets the socket connections IP address and port to the specified values. |
void |
setDebug(boolean bState)
Deprecated. Do not use this method; use setDebugState instead |
void |
setDebugState(int nState)
Puts the class into a debug diagnostic state. |
void |
setOKtoSendTrue()
Triggers the SocketConnection's thread that it is OK to send the next queued message. |
void |
setTimeout(int timeout)
Sets the socket connection's receive timeout in milliseconds. |
boolean |
write(byte[] data)
Writes data to the output stream of the Socket connection. |
boolean |
writeQueued(byte[] data)
Write data to the SocketConnection's output stream if output is OK, otherwise the output is queued awaiting send until OK-to-send is triggered via setOKtoSendTrue() |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int CONNECTED
public static final int TIMEOUT
public static final int CLOSED
public static final int INVALID_HOST
public static final int FAILED_CONNECT
public static final int INFINITE
public static final java.lang.String className
Constructor Detail |
public SocketConnection(java.net.InetAddress addr, int port, int bufferSize, SocketConnectionListener listener)
addr
- InetAddress object indicating the host to connect toport
- integer port number to connect tobufferSize
- integer size of maximum receive bufferlistener
- SocketReceiveHandler object that will be called when data is received on a
sockect or when an error occurs.public SocketConnection(java.lang.String host, int port, int bufferSize, SocketConnectionListener listener)
host
- String name of host to connect toport
- port number to connect tobufferSize
- integer size of maximum receive bufferlistener
- SocketReceiveHandler object that will be called when data is received on a
sockect or when an error occurs.public SocketConnection(java.net.InetAddress addr, int port, int bufferSize, SocketConnectionListener listener, int timeout)
addr
- host String name of host to connect toport
- port number to connect tobufferSize
- integer size of maximum receive bufferlistener
- SocketReceiveHandler object that will be called when data is received on a
sockect or when an error occurs.timeout
- number of milliseconds to wait for received datapublic SocketConnection(java.lang.String host, int port, int bufferSize, SocketConnectionListener listener, int timeout)
host
- String name of host to connect toport
- port number to connect tobufferSize
- integer size of maximum receive bufferlistener
- SocketReceiveHandler object that will be called when data is received on a
sockect or when an error occurs.timeout
- number of milliseconds to wait for received datapublic SocketConnection(java.net.InetAddress addr, int port, int bufferSize, SocketConnectionListener listener, int timeout, boolean TcpNoDelayOn)
addr
- host String name of host to connect toport
- port number to connect tobufferSize
- integer size of maximum receive bufferlistener
- SocketReceiveHandler object that will be called when data is received on a
sockect or when an error occurs.timeout
- number of milliseconds to wait for received dataTcpNoDelayOn
- Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm)public SocketConnection(java.lang.String host, int port, int bufferSize, SocketConnectionListener listener, int timeout, boolean TcpNoDelayOn)
host
- String name of host to connect toport
- port number to connect tobufferSize
- integer size of maximum receive bufferlistener
- SocketReceiveHandler object that will be called when data is received on a
sockect or when an error occurs.timeout
- number of milliseconds to wait for received dataTcpNoDelayOn
- Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm)Method Detail |
public void initConnection(java.lang.String addrStr, int port, int bufferSize, SocketConnectionListener listener, int timeout, boolean TcpNoDelayOn)
public void initConnection(java.lang.String addrStr, int port, int bufferSize, SocketConnectionListener listener, int timeout)
public boolean setAddressAndPort(java.lang.String host, int port)
host
- String containing the new host name to connect to.port
- integer value containing the new port number to connect to.
public boolean setAddressAndPort(java.net.InetAddress addr, int port)
addr
- InetAddress object containing the new IP addressport
- integer value containing the new port.
public void setTimeout(int timeout)
timeout
- [0..n]public boolean connect()
public void disconnect()
public boolean isConnected()
public void dispose()
public void finalize()
public boolean write(byte[] data)
data
- byte array containing data to write
public boolean writeQueued(byte[] data)
data
- byte array containing data to send.
public void flushQueue(boolean send)
send
- boolean flag indicating if the queued messages should be send (true) or
discarded (false)public void setOKtoSendTrue()
public void run()
public void setDebug(boolean bState)
bState
- public void setDebugState(int nState)
nState
- public int getDebugState()
public void log(int level, java.lang.String msg)
level
- msg
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |