Methods Summary |
---|
protected void | _connectAction_()Because there are so many connect() methods, the _connectAction_()
method is provided as a means of performing some action immediately
after establishing a connection, rather than reimplementing all
of the connect() methods. The last action performed by every
connect() method after opening a socket is to call this method.
This method sets the timeout on the just opened socket to the default
timeout set by {@link #setDefaultTimeout setDefaultTimeout() },
sets _input_ and _output_ to the socket's InputStream and OutputStream
respectively, and sets _isConnected_ to true.
Subclasses overriding this method should start by calling
super._connectAction_() first to ensure the
initialization of the aforementioned protected variables.
_socket_.setSoTimeout(_timeout_);
_input_ = _socket_.getInputStream();
_output_ = _socket_.getOutputStream();
_isConnected_ = true;
|
public void | connect(java.net.InetAddress host, int port)Opens a Socket connected to a remote host at the specified port and
originating from the current host at a system assigned port.
Before returning, {@link #_connectAction_ _connectAction_() }
is called to perform connection initialization actions.
_socket_ = _socketFactory_.createSocket(host, port);
_connectAction_();
|
public void | connect(java.lang.String hostname, int port)Opens a Socket connected to a remote host at the specified port and
originating from the current host at a system assigned port.
Before returning, {@link #_connectAction_ _connectAction_() }
is called to perform connection initialization actions.
_socket_ = _socketFactory_.createSocket(hostname, port);
_connectAction_();
|
public void | connect(java.net.InetAddress host, int port, java.net.InetAddress localAddr, int localPort)Opens a Socket connected to a remote host at the specified port and
originating from the specified local address and port.
Before returning, {@link #_connectAction_ _connectAction_() }
is called to perform connection initialization actions.
_socket_ = _socketFactory_.createSocket(host, port, localAddr, localPort);
_connectAction_();
|
public void | connect(java.lang.String hostname, int port, java.net.InetAddress localAddr, int localPort)Opens a Socket connected to a remote host at the specified port and
originating from the specified local address and port.
Before returning, {@link #_connectAction_ _connectAction_() }
is called to perform connection initialization actions.
_socket_ =
_socketFactory_.createSocket(hostname, port, localAddr, localPort);
_connectAction_();
|
public void | connect(java.net.InetAddress host)Opens a Socket connected to a remote host at the current default port
and originating from the current host at a system assigned port.
Before returning, {@link #_connectAction_ _connectAction_() }
is called to perform connection initialization actions.
connect(host, _defaultPort_);
|
public void | connect(java.lang.String hostname)Opens a Socket connected to a remote host at the current default
port and originating from the current host at a system assigned port.
Before returning, {@link #_connectAction_ _connectAction_() }
is called to perform connection initialization actions.
connect(hostname, _defaultPort_);
|
public void | disconnect()Disconnects the socket connection.
You should call this method after you've finished using the class
instance and also before you call
{@link #connect connect() }
again. _isConnected_ is set to false, _socket_ is set to null,
_input_ is set to null, and _output_ is set to null.
_socket_.close();
_input_.close();
_output_.close();
_socket_ = null;
_input_ = null;
_output_ = null;
_isConnected_ = false;
|
public int | getDefaultPort()Returns the current value of the default port (stored in
{@link #_defaultPort_ _defaultPort_ }).
return _defaultPort_;
|
public int | getDefaultTimeout()Returns the default timeout in milliseconds that is used when
opening a socket.
return _timeout_;
|
public java.net.InetAddress | getLocalAddress()Returns the local address to which the client's socket is bound.
return _socket_.getLocalAddress();
|
public int | getLocalPort()Returns the port number of the open socket on the local host used
for the connection.
return _socket_.getLocalPort();
|
public java.net.InetAddress | getRemoteAddress()
return _socket_.getInetAddress();
|
public int | getRemotePort()Returns the port number of the remote host to which the client is
connected.
return _socket_.getPort();
|
public int | getSoLinger()Returns the current SO_LINGER timeout of the currently opened socket.
return _socket_.getSoLinger();
|
public int | getSoTimeout()Returns the timeout in milliseconds of the currently opened socket.
return _socket_.getSoTimeout();
|
public boolean | getTcpNoDelay()Returns true if Nagle's algorithm is enabled on the currently opened
socket.
return _socket_.getTcpNoDelay();
|
public boolean | isConnected()Returns true if the client is currently connected to a server.
return _isConnected_;
|
public void | setDefaultPort(int port)Sets the default port the SocketClient should connect to when a port
is not specified. The {@link #_defaultPort_ _defaultPort_ }
variable stores this value. If never set, the default port is equal
to zero.
_defaultPort_ = port;
|
public void | setDefaultTimeout(int timeout)Set the default timeout in milliseconds to use when opening a socket.
This value is only used previous to a call to
{@link #connect connect()}
and should not be confused with {@link #setSoTimeout setSoTimeout()}
which operates on an the currently opened socket. _timeout_ contains
the new timeout value.
_timeout_ = timeout;
|
public void | setSoLinger(boolean on, int val)Sets the SO_LINGER timeout on the currently opened socket.
_socket_.setSoLinger(on, val);
|
public void | setSoTimeout(int timeout)Set the timeout in milliseconds of a currently open connection.
Only call this method after a connection has been opened
by {@link #connect connect()}.
_socket_.setSoTimeout(timeout);
|
public void | setSocketFactory(SocketFactory factory)Sets the SocketFactory used by the SocketClient to open socket
connections. If the factory value is null, then a default
factory is used (only do this to reset the factory after having
previously altered it).
if (factory == null)
_socketFactory_ = __DEFAULT_SOCKET_FACTORY;
else
_socketFactory_ = factory;
|
public void | setTcpNoDelay(boolean on)Enables or disables the Nagle's algorithm (TCP_NODELAY) on the
currently opened socket.
_socket_.setTcpNoDelay(on);
|
public boolean | verifyRemote(java.net.Socket socket)Verifies that the remote end of the given socket is connected to the
the same host that the SocketClient is currently connected to. This
is useful for doing a quick security check when a client needs to
accept a connection from a server, such as an FTP data connection or
a BSD R command standard error stream.
InetAddress host1, host2;
host1 = socket.getInetAddress();
host2 = getRemoteAddress();
return host1.equals(host2);
|