Diamond Control Suite 3.0

diamondedge.swing
Class DsSocket

java.lang.Object
  extended by java.awt.Component
      extended by diamondedge.swing.DsSocket
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class DsSocket
extends Component

DsSocket allows TCP or UDP communication to occur with the data events showing up on the UI event queue in an assynchronous fashion. This allows for an easier mechanism to hook up network communcations to a user interface

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int CLOSE_EVENT
           
static int CLOSED
           
static int CLOSING
           
static int CONNECT_EVENT
           
static int CONNECTED
           
static int CONNECTING
           
static int CONNECTION_PENDING
           
static int CONNECTION_REQUEST_EVENT
           
static int DATA_ARRIVAL_EVENT
           
static int ERROR
           
static int ERROR_EVENT
           
static int HOST_RESOLVED
           
static int LISTENING
           
static int OPEN
           
static int RESOLVING_HOST
           
static int SEND_COMPLETE_EVENT
           
static int SEND_PROGRESS_EVENT
           
static int TCP_PROTOCOL
           
static int UDP_PROTOCOL
           
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DsSocket()
           
 
Method Summary
 void accept()
          Accept an incoming connection request
 void addSocketListener(SocketListener l)
           
 void bind(int LocalPort)
          Binds socket to specific port and adapter
 void close()
          Close current connection
 void connect()
          Connect to the remote computer
 void connect(String remoteHostName, int remotePort)
          Connect to the remote computer
protected static byte[] convertToBytes(Variant var)
           
protected static void convertToVariant(byte[] b, Variant var, int type)
           
 int getBytesReceived()
          Returns the number of bytes received on this connection
 void getData(Variant var, int type)
          Retrieve data sent by the remote computer
 String getLocalHostName()
          Returns the local machine name
 String getLocalIP()
          Returns the local machine IP address
 int getLocalPort()
          Returns the port used on the local computer
 int getProtocol()
          Returns the socket protocol
 InetAddress getRemoteHostAddress()
          Returns the InetAddress object for the remote computer
 String getRemoteHostIP()
          Returns the remote host IP address
 String getRemoteHostName()
          Returns the name used to identify the remote computer
 int getRemotePort()
          Returns the port to be connected to on the remote computer
 Socket getSocket()
          Returns the tcp socket object
 int getState()
          Returns the state of the socket connection
 int getUdpBufferLength()
          Returns the buffer length used to receive DatagramPackets using UDP_PROTOCOL.
 DatagramSocket getUdpSocket()
          Returns the udp socket object
 void listen()
          Listen for incoming connection requests
 void peekData(Variant var, int type)
          Look at incoming data without removing it from the buffer
 void removeSocketListener(SocketListener l)
           
 void sendData(byte[] data)
           
 void sendData(String data)
           
 void sendData(Variant data)
          Send data to remote computer
 void setLocalPort(int val)
          Sets the port used on the local computer
 void setProtocol(int val)
          Sets the socket protocol
 void setRemoteHostName(String hostName)
          Sets the name used to identify the remote computer
 void setRemotePort(int val)
          Sets the port to be connected to on the remote computer
 void setUdpBufferLength(int val)
          Sets the buffer length used to receive DatagramPackets using UDP_PROTOCOL.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TCP_PROTOCOL

public static final int TCP_PROTOCOL
See Also:
Constant Field Values

UDP_PROTOCOL

public static final int UDP_PROTOCOL
See Also:
Constant Field Values

CLOSED

public static final int CLOSED
See Also:
Constant Field Values

OPEN

public static final int OPEN
See Also:
Constant Field Values

LISTENING

public static final int LISTENING
See Also:
Constant Field Values

CONNECTION_PENDING

public static final int CONNECTION_PENDING
See Also:
Constant Field Values

RESOLVING_HOST

public static final int RESOLVING_HOST
See Also:
Constant Field Values

HOST_RESOLVED

public static final int HOST_RESOLVED
See Also:
Constant Field Values

CONNECTING

public static final int CONNECTING
See Also:
Constant Field Values

CONNECTED

public static final int CONNECTED
See Also:
Constant Field Values

CLOSING

public static final int CLOSING
See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

ERROR_EVENT

public static final int ERROR_EVENT
See Also:
Constant Field Values

DATA_ARRIVAL_EVENT

public static final int DATA_ARRIVAL_EVENT
See Also:
Constant Field Values

CONNECT_EVENT

public static final int CONNECT_EVENT
See Also:
Constant Field Values

CONNECTION_REQUEST_EVENT

public static final int CONNECTION_REQUEST_EVENT
See Also:
Constant Field Values

CLOSE_EVENT

public static final int CLOSE_EVENT
See Also:
Constant Field Values

SEND_PROGRESS_EVENT

public static final int SEND_PROGRESS_EVENT
See Also:
Constant Field Values

SEND_COMPLETE_EVENT

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

DsSocket

public DsSocket()
Method Detail

setUdpBufferLength

public void setUdpBufferLength(int val)
Sets the buffer length used to receive DatagramPackets using UDP_PROTOCOL. Defaults to 4096 bytes.


getUdpBufferLength

public int getUdpBufferLength()
Returns the buffer length used to receive DatagramPackets using UDP_PROTOCOL. Defaults to 4096 bytes.


getProtocol

public int getProtocol()
Returns the socket protocol


setProtocol

public void setProtocol(int val)
Sets the socket protocol

Parameters:
val - One of: TCP_PROTOCOL, UDP_PROTOCOL

getLocalHostName

public String getLocalHostName()
Returns the local machine name


getLocalIP

public String getLocalIP()
Returns the local machine IP address


getLocalPort

public int getLocalPort()
Returns the port used on the local computer


setLocalPort

public void setLocalPort(int val)
Sets the port used on the local computer


getSocket

public Socket getSocket()
Returns the tcp socket object


getUdpSocket

public DatagramSocket getUdpSocket()
Returns the udp socket object


getRemoteHostIP

public String getRemoteHostIP()
Returns the remote host IP address


getRemotePort

public int getRemotePort()
Returns the port to be connected to on the remote computer


setRemotePort

public void setRemotePort(int val)
Sets the port to be connected to on the remote computer


getRemoteHostName

public String getRemoteHostName()
Returns the name used to identify the remote computer


setRemoteHostName

public void setRemoteHostName(String hostName)
                       throws UnknownHostException
Sets the name used to identify the remote computer

Throws:
UnknownHostException

getRemoteHostAddress

public InetAddress getRemoteHostAddress()
Returns the InetAddress object for the remote computer


getState

public int getState()
Returns the state of the socket connection


getBytesReceived

public int getBytesReceived()
Returns the number of bytes received on this connection


connect

public void connect(String remoteHostName,
                    int remotePort)
             throws IOException,
                    UnknownHostException
Connect to the remote computer

Throws:
IOException
UnknownHostException

connect

public void connect()
             throws IOException,
                    UnknownHostException
Connect to the remote computer

Throws:
IOException
UnknownHostException

listen

public void listen()
Listen for incoming connection requests


accept

public void accept()
Accept an incoming connection request


sendData

public void sendData(Variant data)
              throws IOException,
                     SocketException
Send data to remote computer

Throws:
IOException
SocketException

sendData

public void sendData(String data)
              throws IOException,
                     SocketException
Throws:
IOException
SocketException

sendData

public void sendData(byte[] data)
              throws IOException,
                     SocketException
Throws:
IOException
SocketException

convertToBytes

protected static byte[] convertToBytes(Variant var)

convertToVariant

protected static void convertToVariant(byte[] b,
                                       Variant var,
                                       int type)

getData

public void getData(Variant var,
                    int type)
Retrieve data sent by the remote computer


peekData

public void peekData(Variant var,
                     int type)
Look at incoming data without removing it from the buffer


close

public void close()
           throws IOException
Close current connection

Throws:
IOException

bind

public void bind(int LocalPort)
Binds socket to specific port and adapter


addSocketListener

public void addSocketListener(SocketListener l)

removeSocketListener

public void removeSocketListener(SocketListener l)

Diamond Control Suite 3.0

Diamond Edge and Diamond Control Suite are trademarks or registered trademarks of Diamond Edge, Inc. Copyright 1999-2005 Diamond Edge, Inc. All Rights Reserved.