SSH Factory

com.jscape.inet.ipclient
Class IpClient

java.lang.Object
  extended bycom.jscape.inet.ipclient.IpClient
Direct Known Subclasses:
IpClientSsh

public class IpClient
extends java.lang.Object

Implements basic functionality of a TCP/IP client connection.

Example usage:

 try {
   // create new IpClient instance with hostname, port and timeout arguments
   IpClient client = new IpClient("10.0.0.1",53,5000);
 

// establish connection with server client.connect();

// obtain OutputStream for sending data to server OutputStream out = client.getOutputStream();

// obtain InputStream for reading data from server InputStream in = client.getInputStream();

// disconnect from server client.disconnect();

} catch(IpClientException ipe) { ipe.printStackTrace(); }


Constructor Summary
IpClient(java.lang.String hostname, int port)
          Creates a new IpClient instance.
IpClient(java.lang.String hostname, int port, int timeout)
          Creates a new IpClient instance.
 
Method Summary
 void addIpClientListener(IpClientListener listener)
          Adds IpClient event listener
 void connect()
          Establishes connection with server.
 void disconnect()
          Closes connection with server.
 java.io.InputStream getInputStream()
          Gets InputStream from socket connection established with server.
 java.io.OutputStream getOutputStream()
          Gets OutputStream from socket connection established with server.
 java.net.Socket getSocket()
          Gets Socket established after invoking the IpClient#connect method.
 void removeIpClientListener(IpClientListener listener)
          Removes an IpClient event listener
 void setInputStream(java.io.InputStream input)
          Replaces InputStream from socket connection established with server.
 void setOutputStream(java.io.OutputStream output)
          Sets OutputStream from socket connection established with server.
 void setSocket(java.net.Socket socket)
          Sets socket replacing current socket with new socket
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IpClient

public IpClient(java.lang.String hostname,
                int port)
Creates a new IpClient instance.

Parameters:
hostname - the server hostname or IP address
port - the server port

IpClient

public IpClient(java.lang.String hostname,
                int port,
                int timeout)
Creates a new IpClient instance.

Parameters:
hostname - the server hostname or IP address
port - the server port
timeout - the timeout for establishing a connection specified in ms (milliseconds)
Method Detail

addIpClientListener

public void addIpClientListener(IpClientListener listener)
Adds IpClient event listener

Parameters:
listener - an IpClientListener

removeIpClientListener

public void removeIpClientListener(IpClientListener listener)
Removes an IpClient event listener

Parameters:
listener - an IpClientListener

connect

public void connect()
             throws IpClientException
Establishes connection with server.

Throws:
IpClientException - if an I/O or network related error occurs

getInputStream

public java.io.InputStream getInputStream()
Gets InputStream from socket connection established with server. IpClient#connect method must be invoked prior to invoking this method.

Returns:
an InputStream or null if connection has been closed or not yet established

setInputStream

public void setInputStream(java.io.InputStream input)
Replaces InputStream from socket connection established with server. IpClient#connect method must be invoked prior to invoking this method.


getOutputStream

public java.io.OutputStream getOutputStream()
Gets OutputStream from socket connection established with server. IpClient#connect method must be invoked prior to invoking this method.

Returns:
an OutputStream or null if connection has been closed or not yet established

setOutputStream

public void setOutputStream(java.io.OutputStream output)
Sets OutputStream from socket connection established with server.

Parameters:
output -

getSocket

public java.net.Socket getSocket()
Gets Socket established after invoking the IpClient#connect method.

Returns:
a Socket
See Also:
connect()

setSocket

public void setSocket(java.net.Socket socket)
               throws IpClientException
Sets socket replacing current socket with new socket

Parameters:
socket - the new socket
Throws:
IpClientException

disconnect

public void disconnect()
                throws IpClientException
Closes connection with server.

Throws:
IpClientException - if an I/O or network related error occurs

SSH Factory

Copyright JSCAPE 2004 All Rights Reserved