com.amx.duet.tools.net.udp
Class DatagramSocketConnection

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.amx.duet.tools.net.udp.DatagramSocketConnection
All Implemented Interfaces:
java.lang.Runnable

public class DatagramSocketConnection
extends java.lang.Thread

This class is used to manage datagram socket connections on a single thread making it safe for AMX masters.

Version:
2.0.5
Author:
CNina

Field Summary
static int FAILED_CREATE_DATAGRAM_SOCKET
           
static int FAILED_DATAGRAM_READ
           
static int FAILED_DATAGRAM_WRITE
           
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
DatagramSocketConnection(java.net.InetAddress addr, int port, int bufferSize, ISocketConnectionListener listener)
          Creates a simple socket connection along with a receive thread for reading the socket.
DatagramSocketConnection(java.net.InetAddress addr, int port, int bufferSize, ISocketConnectionListener listener, int timeout)
          Creates a simple socket along with a receive thread for reading the socket.
DatagramSocketConnection(java.lang.String host, int port, int bufferSize, ISocketConnectionListener listener)
          Creates a simple socket along with a receive thread for reading the socket.
DatagramSocketConnection(java.lang.String host, int port, int bufferSize, ISocketConnectionListener listener, int timeout)
          Creates a simple socket along with a receive thread for reading the socket.
 
Method Summary
 void dispose()
          Closes this socket connection and sets it to null.
 int getDebugState()
          Gets the current diagnostic state.
 void run()
           
 void setAddressAndPort(java.lang.String host, int port)
          Sets the IP address and Port to be used with a datagram packet.
 void setDebugState(int nState)
          Puts the class into a debug diagnostic state.
 boolean write(byte[] data)
          Writes data to the datagram Socket.
 
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

INVALID_HOST

public static final int INVALID_HOST
See Also:
Constant Field Values

FAILED_CREATE_DATAGRAM_SOCKET

public static final int FAILED_CREATE_DATAGRAM_SOCKET
See Also:
Constant Field Values

FAILED_DATAGRAM_WRITE

public static final int FAILED_DATAGRAM_WRITE
See Also:
Constant Field Values

FAILED_DATAGRAM_READ

public static final int FAILED_DATAGRAM_READ
See Also:
Constant Field Values

TIMEOUT

public static final int TIMEOUT
See Also:
Constant Field Values

INFINITE

public static final int INFINITE
See Also:
Constant Field Values
Constructor Detail

DatagramSocketConnection

public DatagramSocketConnection(java.net.InetAddress addr,
                                int port,
                                int bufferSize,
                                ISocketConnectionListener listener)
Creates a simple socket connection along with a receive thread for reading the socket. When data is received on the socket, listener will be called. The socket receive has no initial timeout value (INFINITE).

Parameters:
addr - InetAddress object indicating the host to connect to
port - integer port number to connect to
bufferSize - integer size of maximum receive buffer
listener - SocketReceiveHandler object that will be called when data is received on a sockect or when an error occurs.

DatagramSocketConnection

public DatagramSocketConnection(java.lang.String host,
                                int port,
                                int bufferSize,
                                ISocketConnectionListener listener)
Creates a simple socket along with a receive thread for reading the socket. When data is received on the socket, listener will be called. The socket receive has no initial timeout value (INFINITE).

Parameters:
host - String name of host to connect to
port - port number to connect to
bufferSize - integer size of maximum receive buffer
listener - SocketReceiveHandler object that will be called when data is received on a sockect or when an error occurs.

DatagramSocketConnection

public DatagramSocketConnection(java.net.InetAddress addr,
                                int port,
                                int bufferSize,
                                ISocketConnectionListener listener,
                                int timeout)
Creates a simple socket along with a receive thread for reading the socket. When data is received on the socket, listener will be called. The socket receive has the specified timeout. If a timeout occurs, the ISocketConnectionListener.handleSocketStatus will be called with a status of TIMEOUT.

Parameters:
addr - host String name of host to connect to
port - port number to connect to
bufferSize - integer size of maximum receive buffer
listener - 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 data

DatagramSocketConnection

public DatagramSocketConnection(java.lang.String host,
                                int port,
                                int bufferSize,
                                ISocketConnectionListener listener,
                                int timeout)
Creates a simple socket along with a receive thread for reading the socket. When data is received on the socket, listener will be called. The socket receive has no initial timeout value (INFINITE). If a timeout occurs, the ISocketConnectionListener.handleSocketStatus will be called with a status of TIMEOUT.

Parameters:
host - String name of host to connect to
port - port number to connect to
bufferSize - integer size of maximum receive buffer
listener - 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 data
Method Detail

setAddressAndPort

public void setAddressAndPort(java.lang.String host,
                              int port)
Sets the IP address and Port to be used with a datagram packet.

Parameters:
host -
port -

dispose

public void dispose()
Closes this socket connection and sets it to null. This method will also terminate the receive thread and release all resources.


write

public boolean write(byte[] data)
Writes data to the datagram Socket.

Parameters:
data - byte array containing data to write
Returns:
true if write was successful, else false

run

public void run()

setDebugState

public void setDebugState(int nState)
Puts the class into a debug diagnostic state.

Parameters:
nState -

getDebugState

public int getDebugState()
Gets the current diagnostic state.

Returns:


Copyright © 2008 AMX LLC. All Rights Reserved.