Java Doc for SocketClient.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache commons net 1.4.1 » org.apache.commons.net 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.net.SocketClient

All known Subclasses:   org.apache.commons.net.DaytimeTCPClient,  org.apache.commons.net.pop3.POP3,  org.apache.commons.net.TimeTCPClient,  org.apache.commons.net.smtp.SMTP,  org.apache.commons.net.DiscardTCPClient,  org.apache.commons.net.bsd.RExecClient,  org.apache.commons.net.CharGenTCPClient,  org.apache.commons.net.telnet.Telnet,  org.apache.commons.net.FingerClient,  org.apache.commons.net.nntp.NNTP,
SocketClient
abstract public class SocketClient (Code)
The SocketClient provides the basic operations that are required of client objects accessing sockets. It is meant to be subclassed to avoid having to rewrite the same code over and over again to open a socket, close a socket, set timeouts, etc. Of special note is the SocketClient.setSocketFactory setSocketFactory method, which allows you to control the type of Socket the SocketClient creates for initiating network connections. This is especially useful for adding SSL or proxy support as well as better support for applets. For example, you could create a org.apache.commons.net.SocketFactory that requests browser security capabilities before creating a socket. All classes derived from SocketClient should use the SocketClient._socketFactory_ _socketFactory_ member variable to create Socket and ServerSocket instances rather than instanting them by directly invoking a constructor. By honoring this contract you guarantee that a user will always be able to provide his own Socket implementations by substituting his own SocketFactory.
author:
   Daniel F. Savarese
See Also:   SocketFactory


Field Summary
final public static  StringNETASCII_EOL
     The end of line character sequence used by most IETF protocols.
protected  int_defaultPort_
     The default port the client should connect to.
protected  InputStream_input_
     The socket's InputStream.
protected  boolean_isConnected_
     A status variable indicating if the client's socket is currently open.
protected  OutputStream_output_
     The socket's OutputStream.
protected  SocketFactory_socketFactory_
     The socket's SocketFactory.
protected  Socket_socket_
     The socket used for the connection.
protected  int_timeout_
     The timeout to use after opening a socket.

Constructor Summary
public  SocketClient()
     Default constructor for SocketClient.

Method 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.
public  voidconnect(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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
Parameters:
  port - The port to connect to on the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened.

public  voidconnect(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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The name of the remote host.
Parameters:
  port - The port to connect to on the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened.

public  voidconnect(InetAddress host, int port, 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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
Parameters:
  localPort - The local port to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened.

public  voidconnect(String hostname, int port, 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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The name of the remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
Parameters:
  localPort - The local port to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened.

public  voidconnect(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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened.

public  voidconnect(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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The name of the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened.

public  voiddisconnect()
     Disconnects the socket connection. You should call this method after you've finished using the class instance and also before you call SocketClient.connect connect() again.
public  intgetDefaultPort()
     Returns the current value of the default port (stored in SocketClient._defaultPort_ _defaultPort_ ).
public  intgetDefaultTimeout()
     Returns the default timeout in milliseconds that is used when opening a socket.
public  InetAddressgetLocalAddress()
     Returns the local address to which the client's socket is bound.
public  intgetLocalPort()
     Returns the port number of the open socket on the local host used for the connection.
public  InetAddressgetRemoteAddress()
    
public  intgetRemotePort()
     Returns the port number of the remote host to which the client is connected.
public  intgetSoLinger()
     Returns the current SO_LINGER timeout of the currently opened socket.

The current SO_LINGER timeout.

public  intgetSoTimeout()
     Returns the timeout in milliseconds of the currently opened socket.
public  booleangetTcpNoDelay()
     Returns true if Nagle's algorithm is enabled on the currently opened socket.
public  booleanisConnected()
     Returns true if the client is currently connected to a server.
public  voidsetDefaultPort(int port)
     Sets the default port the SocketClient should connect to when a port is not specified.
public  voidsetDefaultTimeout(int timeout)
     Set the default timeout in milliseconds to use when opening a socket. This value is only used previous to a call to SocketClient.connect connect() and should not be confused with SocketClient.setSoTimeout setSoTimeout() which operates on an the currently opened socket.
public  voidsetSoLinger(boolean on, int val)
     Sets the SO_LINGER timeout on the currently opened socket.
public  voidsetSoTimeout(int timeout)
     Set the timeout in milliseconds of a currently open connection.
public  voidsetSocketFactory(SocketFactory factory)
     Sets the SocketFactory used by the SocketClient to open socket connections.
public  voidsetTcpNoDelay(boolean on)
     Enables or disables the Nagle's algorithm (TCP_NODELAY) on the currently opened socket.
public  booleanverifyRemote(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.

Field Detail
NETASCII_EOL
final public static String NETASCII_EOL(Code)
The end of line character sequence used by most IETF protocols. That is a carriage return followed by a newline: "\r\n"



_defaultPort_
protected int _defaultPort_(Code)
The default port the client should connect to.



_input_
protected InputStream _input_(Code)
The socket's InputStream.



_isConnected_
protected boolean _isConnected_(Code)
A status variable indicating if the client's socket is currently open.



_output_
protected OutputStream _output_(Code)
The socket's OutputStream.



_socketFactory_
protected SocketFactory _socketFactory_(Code)
The socket's SocketFactory.



_socket_
protected Socket _socket_(Code)
The socket used for the connection.



_timeout_
protected int _timeout_(Code)
The timeout to use after opening a socket.




Constructor Detail
SocketClient
public SocketClient()(Code)
Default constructor for SocketClient. Initializes _socket_ to null, _timeout_ to 0, _defaultPort to 0, _isConnected_ to false, and _socketFactory_ to a shared instance of org.apache.commons.net.DefaultSocketFactory .




Method Detail
_connectAction_
protected void _connectAction_() throws IOException(Code)
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 SocketClient.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.




connect
public void connect(InetAddress host, int port) throws SocketException, IOException(Code)
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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
Parameters:
  port - The port to connect to on the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.




connect
public void connect(String hostname, int port) throws SocketException, IOException(Code)
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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The name of the remote host.
Parameters:
  port - The port to connect to on the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.
exception:
  UnknownHostException - If the hostname cannot be resolved.




connect
public void connect(InetAddress host, int port, InetAddress localAddr, int localPort) throws SocketException, IOException(Code)
Opens a Socket connected to a remote host at the specified port and originating from the specified local address and port. Before returning, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
Parameters:
  localPort - The local port to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.




connect
public void connect(String hostname, int port, InetAddress localAddr, int localPort) throws SocketException, IOException(Code)
Opens a Socket connected to a remote host at the specified port and originating from the specified local address and port. Before returning, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The name of the remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
Parameters:
  localPort - The local port to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.
exception:
  UnknownHostException - If the hostname cannot be resolved.




connect
public void connect(InetAddress host) throws SocketException, IOException(Code)
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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.




connect
public void connect(String hostname) throws SocketException, IOException(Code)
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, SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The name of the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.
exception:
  UnknownHostException - If the hostname cannot be resolved.




disconnect
public void disconnect() throws IOException(Code)
Disconnects the socket connection. You should call this method after you've finished using the class instance and also before you call SocketClient.connect connect() again. _isConnected_ is set to false, _socket_ is set to null, _input_ is set to null, and _output_ is set to null.


exception:
  IOException - If there is an error closing the socket.




getDefaultPort
public int getDefaultPort()(Code)
Returns the current value of the default port (stored in SocketClient._defaultPort_ _defaultPort_ ).

The current value of the default port.




getDefaultTimeout
public int getDefaultTimeout()(Code)
Returns the default timeout in milliseconds that is used when opening a socket.

The default timeout in milliseconds that is used whenopening a socket.




getLocalAddress
public InetAddress getLocalAddress()(Code)
Returns the local address to which the client's socket is bound.

The local address to which the client's socket is bound.




getLocalPort
public int getLocalPort()(Code)
Returns the port number of the open socket on the local host used for the connection.

The port number of the open socket on the local host usedfor the connection.




getRemoteAddress
public InetAddress getRemoteAddress()(Code)
The remote address to which the client is connected.



getRemotePort
public int getRemotePort()(Code)
Returns the port number of the remote host to which the client is connected.

The port number of the remote host to which the client isconnected.




getSoLinger
public int getSoLinger() throws SocketException(Code)
Returns the current SO_LINGER timeout of the currently opened socket.

The current SO_LINGER timeout. If SO_LINGER is disabled returns-1.
exception:
  SocketException - If the operation fails.




getSoTimeout
public int getSoTimeout() throws SocketException(Code)
Returns the timeout in milliseconds of the currently opened socket.

The timeout in milliseconds of the currently opened socket.
exception:
  SocketException - If the operation fails.




getTcpNoDelay
public boolean getTcpNoDelay() throws SocketException(Code)
Returns true if Nagle's algorithm is enabled on the currently opened socket.

True if Nagle's algorithm is enabled on the currently openedsocket, false otherwise.
exception:
  SocketException - If the operation fails.




isConnected
public boolean isConnected()(Code)
Returns true if the client is currently connected to a server.

True if the client is currently connected to a server,false otherwise.




setDefaultPort
public void setDefaultPort(int port)(Code)
Sets the default port the SocketClient should connect to when a port is not specified. The SocketClient._defaultPort_ _defaultPort_ variable stores this value. If never set, the default port is equal to zero.


Parameters:
  port - The default port to set.




setDefaultTimeout
public void setDefaultTimeout(int timeout)(Code)
Set the default timeout in milliseconds to use when opening a socket. This value is only used previous to a call to SocketClient.connect connect() and should not be confused with SocketClient.setSoTimeout setSoTimeout() which operates on an the currently opened socket. _timeout_ contains the new timeout value.


Parameters:
  timeout - The timeout in milliseconds to use for the socketconnection.




setSoLinger
public void setSoLinger(boolean on, int val) throws SocketException(Code)
Sets the SO_LINGER timeout on the currently opened socket.


Parameters:
  on - True if linger is to be enabled, false if not.
Parameters:
  val - The linger timeout (in hundredths of a second?)
exception:
  SocketException - If the operation fails.




setSoTimeout
public void setSoTimeout(int timeout) throws SocketException(Code)
Set the timeout in milliseconds of a currently open connection. Only call this method after a connection has been opened by SocketClient.connect connect() .


Parameters:
  timeout - The timeout in milliseconds to use for the currentlyopen socket connection.
exception:
  SocketException - If the operation fails.




setSocketFactory
public void setSocketFactory(SocketFactory factory)(Code)
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).


Parameters:
  factory - The new SocketFactory the SocketClient should use.




setTcpNoDelay
public void setTcpNoDelay(boolean on) throws SocketException(Code)
Enables or disables the Nagle's algorithm (TCP_NODELAY) on the currently opened socket.


Parameters:
  on - True if Nagle's algorithm is to be enabled, false if not.
exception:
  SocketException - If the operation fails.




verifyRemote
public boolean verifyRemote(Socket socket)(Code)
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.

True if the remote hosts are the same, false if not.




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.