gov.sandia.ccaffeine.dc.user_iface.MVC
Class ClientSocket

java.lang.Object
  extended by gov.sandia.ccaffeine.dc.user_iface.MVC.ClientSocket

public class ClientSocket
extends java.lang.Object


Field Summary
protected  java.io.InputStream inputStream
           
protected  java.io.LineNumberReader lineNumberReader
           
protected  java.lang.Object lockRead
           
protected  java.lang.Object lockWrite
           
protected  java.io.OutputStream outputStream
           
protected  java.io.PrintStream printStream
           
protected  java.net.Socket socket
           
 
Constructor Summary
ClientSocket()
          Create a ClientSocket.
 
Method Summary
 void close()
          Close the communication link with the cca server.
 java.net.InetAddress getInetAddress()
          Get the IP address of the socket
 java.io.InputStream getInputStream()
          Return the input stream from the cca server.
 java.io.OutputStream getOutputStream()
          Return the output stream to the cca server.
 void open(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          Open a connection link to the cca server.
 void open(java.lang.String nameOfServerMachine, int port)
          Open a connection link to the cca server.
 void openAndSetTimeout(java.lang.String nameOfServerMachine, int port, int timeout)
          Open a connection link to the cca server.
 void print(java.lang.String message)
          Send a message to the cca server
 void println(java.lang.String message)
          Send a message to the cca server
 int read(byte[] buffer)
          Reads some number of bytes from the input stream and stores them into the buffer array b.
 java.lang.String readLine()
           
 void write(byte[] buffer, int offset, int length)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputStream

protected java.io.InputStream inputStream

lineNumberReader

protected java.io.LineNumberReader lineNumberReader

outputStream

protected java.io.OutputStream outputStream

printStream

protected java.io.PrintStream printStream

socket

protected java.net.Socket socket

lockRead

protected java.lang.Object lockRead

lockWrite

protected java.lang.Object lockWrite
Constructor Detail

ClientSocket

public ClientSocket()
Create a ClientSocket.

Method Detail

open

public void open(java.lang.String nameOfServerMachine,
                 int port)
          throws java.net.ConnectException
Open a connection link to the cca server.

Parameters:
nameOfServerMachine - The name of the machine that contains the cca server.
port - The port number that the cca server is using to provide services
Throws:
java.net.ConnectException - Thrown if we can not establish a connection with the cca server.

openAndSetTimeout

public void openAndSetTimeout(java.lang.String nameOfServerMachine,
                              int port,
                              int timeout)
                       throws java.net.ConnectException
Open a connection link to the cca server.

Parameters:
nameOfServerMachine - The name of the machine that contains the cca server.
port - The port number that the cca server is using to provide services
Throws:
java.net.ConnectException - Thrown if we can not establish a connection with the cca server.

open

public void open(java.io.InputStream inputStream,
                 java.io.OutputStream outputStream)
Open a connection link to the cca server.

Parameters:
nameOfServerMachine - The name of the machine that contains the cca server.
port - The port number that the cca server is using to provide services
Throws:
java.net.ConnectException - Thrown if we can not establish a connection with the cca server.

close

public void close()
Close the communication link with the cca server.


readLine

public java.lang.String readLine()
                          throws java.io.IOException
Throws:
java.io.IOException

print

public void print(java.lang.String message)
Send a message to the cca server

Parameters:
message - The string we are sending to the cca server.

println

public void println(java.lang.String message)
Send a message to the cca server

Parameters:
message - The string we are sending to the cca server.

write

public void write(byte[] buffer,
                  int offset,
                  int length)
           throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

Parameters:
buffer - The data
offset - The start offset in the data
length - The number of bytes to write
Throws:
java.io.IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

read

public int read(byte[] buffer)
         throws java.io.IOException
Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

Parameters:
buffer - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.

getInetAddress

public java.net.InetAddress getInetAddress()
Get the IP address of the socket

Returns:
The IP address of the socket.

getInputStream

public java.io.InputStream getInputStream()
Return the input stream from the cca server.

Returns:
The input stream from the cca server

getOutputStream

public java.io.OutputStream getOutputStream()
Return the output stream to the cca server.

Returns:
The output stream to the cca server