com.BobCo.datalinks
Class TCPIPDataLink

java.lang.Object
  extended bycom.BobCo.datalinks.TCPIPDataLink
All Implemented Interfaces:
com.tivoli.twg.libs.TWGDataLink

public class TCPIPDataLink
extends java.lang.Object
implements com.tivoli.twg.libs.TWGDataLink

Sample Director TCP/IP-base TWGDataLink implementation. This class implements a sample TCP/IP based communication driver for supporting communications between the Director Console and Server. The sample provides all the required methods, defined in the TWGDataLink interface, to support server-based and console-based use of this class for unencrypted TCP/IP-based communications.

The class implementation supports an optional initialization string, which currently only supports an override value for the IP port number used by the server-based implmentation. If provided, the string can consist of a number representing the decimal value for the server's port address (default is 2034).

Any modification of this sample should use a different port address default.

See Also:
TWGDataLink

Field Summary
protected static int default_portnum
          Default port number for server socket (set to 2034)
protected  boolean is_inited
           
protected  boolean is_server_sock
           
protected  int portnum
           
protected  java.net.ServerSocket server_sock
           
protected  java.net.Socket sock
           
 
Constructor Summary
  TCPIPDataLink()
          Default constructor for TCPIPDataLink.
protected TCPIPDataLink(java.net.Socket s)
          Internal constructor used by server TCPIPDataLink to build instances when sessions are accepted.
 
Method Summary
 void TWGCloseLink()
          Close connection to server or console.
 java.lang.String TWGGetHostname()
          Return string representing host associated with link
 java.lang.String TWGGetLinkDriverName(java.util.Locale loc)
          Return string representing name of data link driver
 void TWGInitializeConsoleLink(java.lang.String init_str)
          Initialize a console TCPIPDataLink instance.
 void TWGInitializeServerLink(java.lang.String init_str)
          Initialize a server TCPIPDataLink instance.
 boolean TWGOpenLink(java.lang.String hostname, long authcode)
          Open connection to server, using given host/target name.
 boolean TWGOpenLink(java.lang.String hostname, java.lang.String userid, java.lang.String password)
          Open connection to server, using given host/target name.
 int TWGReadData(byte[] b, int off, int len)
          Read data from opened connection.
 com.tivoli.twg.libs.TWGDataLink TWGServerListen()
          Listen for link from console to a server TCPIPDataLink.
 void TWGWriteData(byte[] b, int off, int len)
          Write data to opened connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

default_portnum

protected static final int default_portnum
Default port number for server socket (set to 2034)

See Also:
Constant Field Values

sock

protected java.net.Socket sock

server_sock

protected java.net.ServerSocket server_sock

is_server_sock

protected boolean is_server_sock

portnum

protected int portnum

is_inited

protected boolean is_inited
Constructor Detail

TCPIPDataLink

public TCPIPDataLink()
Default constructor for TCPIPDataLink. Initializes attributes.


TCPIPDataLink

protected TCPIPDataLink(java.net.Socket s)
Internal constructor used by server TCPIPDataLink to build instances when sessions are accepted.

Parameters:
s - - socket to use for session
Method Detail

TWGInitializeConsoleLink

public void TWGInitializeConsoleLink(java.lang.String init_str)
                              throws java.io.IOException,
                                     com.tivoli.twg.libs.TWGInitParmException,
                                     com.tivoli.twg.libs.TWGLinkNotSupportedException
Initialize a console TCPIPDataLink instance. Passes in a parameter string which can either be null or include a decimal number providing an override to the default port number (or * for no override). Called after constructor and before TWGOpenLink() is called.

Specified by:
TWGInitializeConsoleLink in interface com.tivoli.twg.libs.TWGDataLink
Parameters:
init_str - - initialization string from link configuration
Throws:
IOException - if communications error
TWGInitParmException - if bad initialization string
TWGLinkNotSupportedException - if link type not supported
java.io.IOException
com.tivoli.twg.libs.TWGInitParmException
com.tivoli.twg.libs.TWGLinkNotSupportedException

TWGOpenLink

public boolean TWGOpenLink(java.lang.String hostname,
                           java.lang.String userid,
                           java.lang.String password)
                    throws java.net.UnknownHostException,
                           java.io.IOException
Open connection to server, using given host/target name. User-id and password are not used for connecting.

Specified by:
TWGOpenLink in interface com.tivoli.twg.libs.TWGDataLink
Parameters:
hostname - - string for identifying target server
userid - - string for userid to attempt for logon
password - - string for password for logon
Returns:
true if connection is successful, or false if not
Throws:
UnknownHostException - if bad hostname
IOException - if communications error
java.net.UnknownHostException
java.io.IOException

TWGOpenLink

public boolean TWGOpenLink(java.lang.String hostname,
                           long authcode)
                    throws java.net.UnknownHostException,
                           java.io.IOException
Open connection to server, using given host/target name. Authentication code not used.

Specified by:
TWGOpenLink in interface com.tivoli.twg.libs.TWGDataLink
Parameters:
hostname - - string for identifying target server
authcode - - long for authentication code
Returns:
true if connection is successful, or false if not
Throws:
UnknownHostException - if bad hostname
IOException - if communications error
java.net.UnknownHostException
java.io.IOException

TWGWriteData

public void TWGWriteData(byte[] b,
                         int off,
                         int len)
                  throws java.io.IOException
Write data to opened connection. Write call only returns when whole data block has been written. Data block is sent as a message which will be read by a single TWGReadData call on the receiving end of the link.

Specified by:
TWGWriteData in interface com.tivoli.twg.libs.TWGDataLink
Parameters:
b - - source buffer
off - - index of first byte to write from buffer
len - - number of bytes to write from buffer
Throws:
IOException - - if error during write operation
java.io.IOException

TWGReadData

public int TWGReadData(byte[] b,
                       int off,
                       int len)
                throws java.io.IOException
Read data from opened connection. Reads next message which was written, as a unit. Whole message is read, and as much as possible is returned in the provided buffer range. The actual length of the message read is always returned.

Specified by:
TWGReadData in interface com.tivoli.twg.libs.TWGDataLink
Parameters:
b - - destination buffer
off - - index of first byte to read into buffer
len - - number of bytes to read into buffer
Returns:
number of bytes in read message: if more than 'len', data was lost due to insufficient buffer space.
Throws:
IOException - - if error during read operation
java.io.IOException

TWGCloseLink

public void TWGCloseLink()
                  throws java.io.IOException
Close connection to server or console.

Specified by:
TWGCloseLink in interface com.tivoli.twg.libs.TWGDataLink
Throws:
java.io.IOException

TWGInitializeServerLink

public void TWGInitializeServerLink(java.lang.String init_str)
                             throws java.io.IOException,
                                    com.tivoli.twg.libs.TWGInitParmException,
                                    com.tivoli.twg.libs.TWGLinkNotSupportedException
Initialize a server TCPIPDataLink instance. Passes in a parameter string which can either be null or include a decimal number providing an override to the default port number (or * for no override).

Specified by:
TWGInitializeServerLink in interface com.tivoli.twg.libs.TWGDataLink
Parameters:
init_str - - initialization string from link configuration
Throws:
IOException - if communications error
TWGInitParmException - if bad initialization string
TWGLinkNotSupportedException - if link type not supported
java.io.IOException
com.tivoli.twg.libs.TWGInitParmException
com.tivoli.twg.libs.TWGLinkNotSupportedException

TWGServerListen

public com.tivoli.twg.libs.TWGDataLink TWGServerListen()
                                                throws java.io.IOException
Listen for link from console to a server TCPIPDataLink. Blocks until a connection occurs, which results in the return of a TCPIPDataLink instance representing the server-to-console connection, or until an error occurs.

Specified by:
TWGServerListen in interface com.tivoli.twg.libs.TWGDataLink
Returns:
a TCPIPDataLink instance for the opened session
Throws:
IOException - on an error or when the server TCPIPDataLink is closed using TWGCloseLink().
java.io.IOException

TWGGetHostname

public java.lang.String TWGGetHostname()
Return string representing host associated with link

Specified by:
TWGGetHostname in interface com.tivoli.twg.libs.TWGDataLink
Returns:
string hostname

TWGGetLinkDriverName

public java.lang.String TWGGetLinkDriverName(java.util.Locale loc)
Return string representing name of data link driver

Specified by:
TWGGetLinkDriverName in interface com.tivoli.twg.libs.TWGDataLink
Parameters:
loc - - locale to be used to return name
Returns:
string name of driver