Sun Adapter for Batch/FTP

com.stc.eways.batchext
Class SocksSocket

java.lang.Object
  extended by java.net.Socket
      extended by com.stc.eways.batchext.SocksSocket

public class SocksSocket
extends java.net.Socket

This class represents a socket through the SOCKS server.

Version:
cvs revision: $Revision: 1.6 $ Last Modified: $Date: 2008/03/04 03:05:52 $
Author:
Harry Liu

Constructor Summary
SocksSocket(java.net.InetAddress remoteIP, int remotePort)
          Constructor.
SocksSocket(java.net.InetAddress remoteIP, int remotePort, java.net.InetAddress localIP, int localPort)
          Constructor.
SocksSocket(java.net.InetAddress remoteIP, int remotePort, java.net.InetAddress localIP, int localPort, SocksChain socksList)
          Constructor.
SocksSocket(java.net.InetAddress remoteIP, int remotePort, SocksChain socksList)
          Constructor.* Creates a data-stream socket and connects it to the specified port number* at the specified IP address.* @param socksList Represents a SOCKS server chain.* @param remoteIP The IP address of the remote host to connect to.* @param remotePort The port number to connect to on remote host.* @throws SocksException If something is wrong with SOCKS.* @throws IOException If an input-output error occurs when creating the socket.
SocksSocket(Socks socks, java.net.InetAddress remoteIP, int remotePort)
          Constructor.
SocksSocket(Socks socks, java.net.InetAddress remoteIP, int remotePort, java.net.InetAddress localIP, int localPort)
          Constructor.
SocksSocket(Socks socks, java.lang.String remoteHost, int remotePort)
          Constructor.
SocksSocket(Socks socks, java.lang.String remoteHost, int remotePort, java.net.InetAddress localIP, int localPort)
          Constructor.
SocksSocket(java.lang.String remoteHost, int remotePort)
          Constructor.
SocksSocket(java.lang.String remoteHost, int remotePort, java.net.InetAddress localIP, int localPort)
          Constructor.
SocksSocket(java.lang.String remoteHost, int remotePort, java.net.InetAddress localIP, int localPort, SocksChain socksList)
          Constructor.
SocksSocket(java.lang.String remoteHost, int remotePort, SocksChain socksList)
          Constructor.
 
Method Summary
 void close()
          Closes the current socket.
 java.net.InetAddress getInetAddress()
          Retrieves the address to which the current socket is connected.
 java.io.InputStream getInputStream()
          Returns an input stream for the current socket.
 boolean getKeepAlive()
          Tests whether the SO_KEEPALIVE option is enabled.
 java.net.InetAddress getLocalAddress()
          Gets the local address to which the current socket is bound.
 int getLocalPort()
          Returns the local port to which the current socket is bound.
 java.io.OutputStream getOutputStream()
          Returns an output stream for the current socket.
 int getPort()
          Returns the remote port to which the current socket is connected.
 int getReceiveBufferSize()
          Gets the value of the SO_RCVBUF option for the current socket, that is the buffer size used by the platform for input on this socket.
 int getSendBufferSize()
          Gets the value of the SO_SNDBUF option for the current socket, that is, the buffer size used by the platform for output on the current socket.
 Socks getSocks()
          Returns the SOCKS server to which the socket is connected.
 SocksChain getSocksList()
          Returns the SOCKS chain to which the current socket is connected.
 int getSoLinger()
          Gets the setting for the SO_LINGER option.
 int getSoTimeout()
          Gets the setting for the SO_TIMEOUT option.
 boolean getTcpNoDelay()
          Tests whether the TCP_NODELAY option is enabled.
static void main(java.lang.String[] args)
          Used to do stand-alone testing.
 void setKeepAlive(boolean on)
          Allows you to enable or disable the SO_KEEPALIVE option.
 void setReceiveBufferSize(int size)
          Sets the SO_RCVBUF option to the specified value for the current DatagramSocket.
 void setSendBufferSize(int size)
          Sets the SO_SNDBUF option to the specified value for the current DatagramSocket.
static void setSocketImplFactory(java.net.SocketImplFactory factory)
          Sets the client socket implementation factory for the current application.
 void setSoLinger(boolean on, int linger)
          Allows you to enable or disable the SO_LINGER option, using the specified linger time, in seconds.
 void setSoTimeout(int timeout)
          Allows you to enable or disable the SO_TIMEOUT option, using the specified timeout, in milliseconds.
 void setTcpNoDelay(boolean on)
          Allows you to enable or disable TCP_NODELAY (Nagle's algorithm).
 void shutdownInput()
          Places the input data stream for the current socket at the "end of the stream." Any data sent to the input stream side of a socket is acknowledged, then silently discarded.
 void shutdownOutput()
          Disables the output data stream for the current socket.
 java.lang.String toString()
          Converts the current socket to a String.
 
Methods inherited from class java.net.Socket
bind, connect, connect, getChannel, getLocalSocketAddress, getOOBInline, getRemoteSocketAddress, getReuseAddress, getTrafficClass, isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown, sendUrgentData, setOOBInline, setPerformancePreferences, setReuseAddress, setTrafficClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SocksSocket

public SocksSocket(Socks socks,
                   java.lang.String remoteHost,
                   int remotePort,
                   java.net.InetAddress localIP,
                   int localPort)
            throws SocksException,
                   java.net.UnknownHostException,
                   java.io.IOException
Constructor. Creates a socket and connects it to the specified remote host on the specified remote port. The socket also binds to the local address and port supplied.

Parameters:
socks - Represent a SOCKS server.
remoteHost - The remote host to connect to.
remotePort - The port number to connect to on the remote host.
localIP - The IP address of the local host that the socket is bound to.
localPort - The local port (on the local host) that the socket is bound to.
Throws:
SocksException - If something is wrong with SOCKS.
java.net.UnknownHostException - If the IP address of the host cannot be determined.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(Socks socks,
                   java.net.InetAddress remoteIP,
                   int remotePort,
                   java.net.InetAddress localIP,
                   int localPort)
            throws SocksException,
                   java.io.IOException
Constructor. Creates a socket and connects it to the specified remote address on the specified remote port. The socket also binds to the local address and port supplied.

Parameters:
socks - Represent a SOCKS server.
remoteIP - The IP address of the remote host to connect to.
remotePort - The port number to connect to on the remote host.
localIP - The IP address of the local host that the socket is bound to.
localPort - The local port on the local host that the socket is bound to.
Throws:
SocksException - If something is wrong with SOCKS.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(Socks socks,
                   java.net.InetAddress remoteIP,
                   int remotePort)
            throws SocksException,
                   java.io.IOException
Constructor. Creates a data-streaming socket and connects it to the specified port number at the specified IP address.

Parameters:
socks - Represent a SOCKS server.
remoteIP - The IP address of the remote host to connect to.
remotePort - The port number to connect to on the remote host.
Throws:
SocksException - If something is wrong with SOCKS.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(Socks socks,
                   java.lang.String remoteHost,
                   int remotePort)
            throws SocksException,
                   java.net.UnknownHostException,
                   java.io.IOException
Constructor. Creates a data-streaming socket and connects it to the specified port number on the named host.

Parameters:
socks - Represent a SOCKS server.
remoteHost - The remote host to connect to.
remotePort - The port number to connect to on the remote host.
Throws:
SocksException - If something is wrong with SOCKS.
java.net.UnknownHostException - If the IP address of the host cannot be determined.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(java.lang.String remoteHost,
                   int remotePort)
            throws SocksException,
                   java.net.UnknownHostException,
                   java.io.IOException
Constructor. Creates a data-streaming socket and connects it to the specified port number on the named host.

Parameters:
remoteHost - The remote host to connect to.
remotePort - The port number to connect to on the remote host.
Throws:
SocksException - If something is wrong with SOCKS.
java.net.UnknownHostException - If the IP address of the host cannot be determined.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(java.lang.String remoteHost,
                   int remotePort,
                   java.net.InetAddress localIP,
                   int localPort)
            throws SocksException,
                   java.net.UnknownHostException,
                   java.io.IOException
Constructor. Creates a socket and connects it to the specified remote host on the specified remote port. The socket also binds to the local address and port supplied.

Parameters:
remoteHost - The remote host to connect to.
remotePort - The port number to connect to on the remote host.
localIP - The IP address of the local host that the socket is bound to.
localPort - The local port on the local host that the socket is bound to.
Throws:
SocksException - If something is wrong with SOCKS.
java.net.UnknownHostException - If the IP address of the host cannot be determined.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(java.net.InetAddress remoteIP,
                   int remotePort)
            throws SocksException,
                   java.io.IOException
Constructor. Creates a data-streaming socket and connects it to the specified port number at the specified IP address.

Parameters:
remoteIP - The IP address of the remote host to connect to.
remotePort - The port number to connect to on the remote host.
Throws:
SocksException - If something is wrong with SOCKS.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(java.net.InetAddress remoteIP,
                   int remotePort,
                   java.net.InetAddress localIP,
                   int localPort)
            throws SocksException,
                   java.io.IOException
Constructor. Creates a socket and connects it to the specified remote host on the specified remote port. The socket also binds to the local address and port supplied.

Parameters:
remoteIP - The IP address of the remote host to connect to.
remotePort - The port number to connect to on the remote host.
localIP - The IP address of the local host that the socket is bound to.
localPort - The local port on the local host that the socket is bound to.
Throws:
SocksException - If something is wrong with SOCKS.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(java.lang.String remoteHost,
                   int remotePort,
                   SocksChain socksList)
            throws SocksException,
                   java.net.UnknownHostException,
                   java.io.IOException
Constructor. Creates a data-stream socket and connects it to the specified port number on the named host.

Parameters:
socksList - Represents a SOCKS server chain.
remoteHost - The remote FTP host to connect to.
remotePort - The port number to connect to on remote host.
Throws:
SocksException - If something is wrong with SOCKS.
java.net.UnknownHostException - If the IP address of the host could not be determined.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(java.lang.String remoteHost,
                   int remotePort,
                   java.net.InetAddress localIP,
                   int localPort,
                   SocksChain socksList)
            throws SocksException,
                   java.net.UnknownHostException,
                   java.io.IOException
Constructor. Creates a socket and connects it to the specified remote FTP host on the specified remote port. The socket also binds to the local address and port supplied.

Parameters:
socksList - Represents a SOCKS server chain.
remoteHost - The remote host to connect to.
remotePort - The port number to connect to on remote host.
localIP - The IP address of the local host that the socket is bound to.
localPort - The local port (on the local host) that the socket is bound to.
Throws:
SocksException - If something is wrong with SOCKS.
java.net.UnknownHostException - If the IP address of the host could not be determined.
java.io.IOException - If an input-output error occurs when creating the socket.

SocksSocket

public SocksSocket(java.net.InetAddress remoteIP,
                   int remotePort,
                   SocksChain socksList)
            throws SocksException,
                   java.io.IOException
Constructor.* Creates a data-stream socket and connects it to the specified port number* at the specified IP address.* @param socksList Represents a SOCKS server chain.* @param remoteIP The IP address of the remote host to connect to.* @param remotePort The port number to connect to on remote host.* @throws SocksException If something is wrong with SOCKS.* @throws IOException If an input-output error occurs when creating the socket.

Throws:
SocksException
java.io.IOException

SocksSocket

public SocksSocket(java.net.InetAddress remoteIP,
                   int remotePort,
                   java.net.InetAddress localIP,
                   int localPort,
                   SocksChain socksList)
            throws SocksException,
                   java.io.IOException
Constructor. Creates a socket and connects it to the specified remote host address on the specified remote port. The socket also binds to the local address and port supplied.

Parameters:
socksList - Represents a SOCKS server chain.
remoteIP - The IP address of the remote host to connect to.
remotePort - The port number to connect to on remote host.
localIP - The IP address of the local host that the socket is bound to.
localPort - The local port (on the local host) that the socket is bound to.
Throws:
SocksException - If something is wrong with SOCKS.
java.io.IOException - If an input-output error occurs when creating the socket.
Method Detail

setSocketImplFactory

public static void setSocketImplFactory(java.net.SocketImplFactory factory)
                                 throws java.io.IOException
Sets the client socket implementation factory for the current application.

Parameters:
factory - The desired factory.
Throws:
java.io.IOException - If an input-output error occurs when setting the socket factory.

close

public void close()
           throws java.io.IOException
Closes the current socket.

Overrides:
close in class java.net.Socket
Throws:
java.io.IOException - If an input-output error occurs when closing the current socket.

getInetAddress

public java.net.InetAddress getInetAddress()
Retrieves the address to which the current socket is connected.

Overrides:
getInetAddress in class java.net.Socket
Returns:
The remote IP address to which the socket is connected.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns an input stream for the current socket.

Overrides:
getInputStream in class java.net.Socket
Returns:
An input stream for reading bytes from the socket.
Throws:
java.io.IOException - If an input-output error occurs when creating the input stream.

getLocalAddress

public java.net.InetAddress getLocalAddress()
Gets the local address to which the current socket is bound.

Overrides:
getLocalAddress in class java.net.Socket
Returns:
The local IP address which binds to the socket.

getLocalPort

public int getLocalPort()
Returns the local port to which the current socket is bound.

Overrides:
getLocalPort in class java.net.Socket
Returns:
The local port number to which the socket is bound.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Returns an output stream for the current socket.

Overrides:
getOutputStream in class java.net.Socket
Returns:
An output stream for writing bytes to the socket.
Throws:
java.io.IOException - If an input-output error occurs when creating the output stream.

getPort

public int getPort()
Returns the remote port to which the current socket is connected.

Overrides:
getPort in class java.net.Socket
Returns:
The remote port number to which the socket is connected.

getReceiveBufferSize

public int getReceiveBufferSize()
                         throws java.net.SocketException
Gets the value of the SO_RCVBUF option for the current socket, that is the buffer size used by the platform for input on this socket.

Overrides:
getReceiveBufferSize in class java.net.Socket
Returns:
The buffer size (an integer).
Throws:
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

getSendBufferSize

public int getSendBufferSize()
                      throws java.net.SocketException
Gets the value of the SO_SNDBUF option for the current socket, that is, the buffer size used by the platform for output on the current socket.

Overrides:
getSendBufferSize in class java.net.Socket
Returns:
The buffer size (an integer).
Throws:
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

getSoLinger

public int getSoLinger()
                throws java.net.SocketException
Gets the setting for the SO_LINGER option. A -1 return means that the option is disabled.

Overrides:
getSoLinger in class java.net.Socket
Returns:
The SO_LINGER value (an integer).
Throws:
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

getSoTimeout

public int getSoTimeout()
                 throws java.net.SocketException
Gets the setting for the SO_TIMEOUT option. A zero return means that the option is disabled (that is, a timeout of infinity).

Overrides:
getSoTimeout in class java.net.Socket
Returns:
The SO_TIMEOUT value (an integer).
Throws:
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

getTcpNoDelay

public boolean getTcpNoDelay()
                      throws java.net.SocketException
Tests whether the TCP_NODELAY option is enabled.

Overrides:
getTcpNoDelay in class java.net.Socket
Returns:
true or false.
Throws:
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

setReceiveBufferSize

public void setReceiveBufferSize(int size)
                          throws java.net.SocketException
Sets the SO_RCVBUF option to the specified value for the current DatagramSocket. The SO_RCVBUF option is used by the platform's networking code as a hint for the size to use to allocate and set the underlying network input-output buffers.

Increasing the buffer size can improve the performance of network input-output for a high-volume connection. However, decreasing the size can help reduce the backlog of incoming data. For UDP, this method sets the maximum size of a packet that can be sent on the current socket.

Because SO_RCVBUF is a hint, applications that want to verify what size the buffers were set to must call getReceiveBufferSize.

Overrides:
setReceiveBufferSize in class java.net.Socket
Parameters:
size - The size to use in setting the receive buffer. size. This value must be greater than zero.
Throws:
java.lang.IllegalArgumentException - If the value is zero or negative.
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

setSendBufferSize

public void setSendBufferSize(int size)
                       throws java.net.SocketException
Sets the SO_SNDBUF option to the specified value for the current DatagramSocket. The SO_SNDBUF option is used by the platform's networking code as a hint for the size to use to allocate and set the underlying network input-output buffers.

Increasing the buffer size can improve the performance of network input-output for a high-volume connection. However, decreasing the size can help reduce the backlog of incoming data. For UDP, this method sets the maximum size of a packet that can be sent on the current socket.

Because SO_SNDBUF is a hint, applications that want to verify what size the buffers were set to must call getSendBufferSize.

Overrides:
setSendBufferSize in class java.net.Socket
Parameters:
size - The size to which to set the send buffer. size. This value must be greater than zero.
Throws:
java.lang.IllegalArgumentException - If the value is zero or negative.
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

setSoLinger

public void setSoLinger(boolean on,
                        int linger)
                 throws java.net.SocketException
Allows you to enable or disable the SO_LINGER option, using the specified linger time, in seconds. If the specified timeout value exceeds 65,535, is reduced to 65,535.

Overrides:
setSoLinger in class java.net.Socket
Parameters:
on - Enables the SO_LINGER option.
linger - How long to linger, if SO_LINGER is enabled.
Throws:
java.lang.IllegalArgumentException - If the linger value is negative.
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Allows you to enable or disable the SO_TIMEOUT option, using the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with the current socket blocks for only the specified amount of time. If the timeout expires, a java.io.InterruptedIOException is raised, though the socket is still valid. This option must be enabled before entering the blocking operation or it does not work. The timeout must be greater than 0. A timeout of zero is interpreted as an infinite timeout.

Overrides:
setSoTimeout in class java.net.Socket
Parameters:
timeout - The timeour time, in milliseconds (an integer).
Throws:
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

setTcpNoDelay

public void setTcpNoDelay(boolean on)
                   throws java.net.SocketException
Allows you to enable or disable TCP_NODELAY (Nagle's algorithm).

Overrides:
setTcpNoDelay in class java.net.Socket
Parameters:
on - true or false.
Throws:
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

toString

public java.lang.String toString()
Converts the current socket to a String.

Overrides:
toString in class java.net.Socket
Returns:
A string representation of the current socket.

getKeepAlive

public boolean getKeepAlive()
                     throws java.net.SocketException
Tests whether the SO_KEEPALIVE option is enabled.

Overrides:
getKeepAlive in class java.net.Socket
Returns:
true or false.
Throws:
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

setKeepAlive

public void setKeepAlive(boolean on)
                  throws java.net.SocketException
Allows you to enable or disable the SO_KEEPALIVE option.

Overrides:
setKeepAlive in class java.net.Socket
Parameters:
on - true or false.
Throws:
java.net.SocketException - If there is an error in the underlying protocol, such as a TCP error.

shutdownInput

public void shutdownInput()
                   throws java.io.IOException
Places the input data stream for the current socket at the "end of the stream." Any data sent to the input stream side of a socket is acknowledged, then silently discarded. If you read from a socket's input stream after invoking shutdownInput() on the socket, the stream returns EOF.

Overrides:
shutdownInput in class java.net.Socket
Throws:
java.io.IOException - If an input-output error occurs when shutting down the current socket.

shutdownOutput

public void shutdownOutput()
                    throws java.io.IOException
Disables the output data stream for the current socket. For a TCP socket, any previously written data is sent followed by TCP's normal connection termination sequence. If you write to a socket output stream after invoking shutdownOutput() on the socket, the stream throws an IOException.

Overrides:
shutdownOutput in class java.net.Socket
Throws:
java.io.IOException - If an input-output error occurs when shutting down the current socket.

main

public static void main(java.lang.String[] args)
Used to do stand-alone testing.

Parameters:
args - Command line parameters.

getSocks

public Socks getSocks()
Returns the SOCKS server to which the socket is connected.

Returns:
The SOCKS server to which the current socket is connected.

getSocksList

public SocksChain getSocksList()
Returns the SOCKS chain to which the current socket is connected.

Returns:
The SOCKS chain to which the socket is connected.

Sun Adapter for Batch/FTP