Cross-Platform C++

ot::net
class TcpNetworkClient  (abstract)

#include "ot/net/TcpNetworkClient.h"

ot::ManagedObject ot::net::FtpClient An abstract base class for utilities that require a TCP/IP connection to a network server. This class doesn't do very much except manage a Socket connection. Unlike a Socket, the connection can be opened and closed multiple times.




Method Summary
 virtual void connect(const String& host, int port, size_t timeoutMS)
         Connects this TcpNetworkClient to a server on the specified host.
protected  virtual RefPtr< Socket > createConnection(const String& host, int port, size_t timeoutMS)
         Protected virtual method to create a Socket connection to the TCP/IP network server.
 virtual void disconnect()
         Disconnects from the server.
protected  virtual int getDefaultPort() const=0
         Virtual member function overridden in derived classes to return a default port number for the network service.
 virtual RefPtr< InputStream > getInputStream() const
         Returns an InputStream for reading from the server.
 virtual RefPtr< InetAddress > getLocalAddress() const
         Returns the local IP Address that the connected socket is bound to.
 virtual RefPtr< OutputStream > getOutputStream() const
         Returns an OutputStream for writing to the server.
 virtual RefPtr< InetAddress > getServerAddress() const
         Returns the IP Address of the remote server to which this TcpNetworkClient is connected.
 virtual int getServerPort() const
         Returns the port number of the remote server to which this TcpNetworkClient is connected.
 virtual bool isConnected() const
         Tests if this TcpNetworkClient is currently connected to a server.
protected  virtual void postConnect(const String& server, int port, size_t timeoutMS)
         Protected function called when a socket connection has been established with the TCP/IP network server.
protected  virtual void preDisconnect()
         Protected function called when a socket connection is about to be closed from the client side.

Methods inherited from class ot::ManagedObject
addRef, getRefCount, onFinalRelease, operator=, release

Method Detail

connect

virtual void connect(const String& host,
                     int port,
                     size_t timeoutMS)
Connects this TcpNetworkClient to a server on the specified host. If the TcpNetworkClient is already connected, no action is taken.

If timeoutMS is specified and is greater than zero, the connection attempt will time-out and a SocketTimeoutException will be thrown if the specified number of milliseconds elapses before the connection is fully established.

If port is less than or equal to zero (the default), then a default port number will be obtained by calling getDefaultPort().

Parameters:
host - the host name of the server
port - the port number of the server
timeoutMS - the time-out value in milliseconds. A value of zero indicates that the client will wait forever, or until the underlying operating system decides that the connection cannot be established.
Exceptions:
IOException - if an error occurs trying to connect to the server
ProtocolException - if an invalid response is received from the server
UnknownHostException - if an error occurs trying to resolve the host name
SocketTimeoutException - if the specified timeout value expires while attempting to connect to the server
See also:
disconnect()

createConnection

protected virtual RefPtr< SocketcreateConnection(const String& host,
                                                    int port,
                                                    size_t timeoutMS)
Protected virtual method to create a Socket connection to the TCP/IP network server. The base class implementation creates a standard socket and attempts to make a TCP/IP connection to the specified server.

Parameters:
host - the host name of the server
port - the port number of the server
timeoutMS - a time out value in milliseconds
Exceptions:
IOException - if an error occurs trying to connect to the server
UnknownHostException - if an error occurs trying to resolve the host name
SocketTimeoutException - if the specified timeout value expires while attempting to connect to the server

disconnect

virtual void disconnect()
Disconnects from the server. It is acceptable to re-connect to another server once disconnect() has been called.

Further calls to disconnect() have no effect.


getDefaultPort

protected virtual int getDefaultPort() const=0
Virtual member function overridden in derived classes to return a default port number for the network service. This is called by connect() when a valid port number has not been provided.


getInputStream

virtual RefPtr< InputStreamgetInputStream() const
Returns an InputStream for reading from the server.

Returns:
an InputStream for reading from the server or null if this TcpNetworkClient is not currently connected.

getLocalAddress

virtual RefPtr< InetAddressgetLocalAddress() const
Returns the local IP Address that the connected socket is bound to.

Returns:
the InetAddress of the local host or null if this TcpNetworkClient is not currently connected.

getOutputStream

virtual RefPtr< OutputStreamgetOutputStream() const
Returns an OutputStream for writing to the server.

Returns:
an OutputStream for writing to the server or null if this TcpNetworkClient is not currently connected.

getServerAddress

virtual RefPtr< InetAddressgetServerAddress() const
Returns the IP Address of the remote server to which this TcpNetworkClient is connected.

Returns:
the InetAddress of the remote host or null if this TcpNetworkClient is not currently connected.

getServerPort

virtual int getServerPort() const
Returns the port number of the remote server to which this TcpNetworkClient is connected.

Returns:
the port number or -1 if this TcpNetworkClient is not currently connected.

isConnected

virtual bool isConnected() const
Tests if this TcpNetworkClient is currently connected to a server.

Returns:
true if connected; false otherwise

postConnect

protected virtual void postConnect(const String& server,
                                   int port,
                                   size_t timeoutMS)
Protected function called when a socket connection has been established with the TCP/IP network server. The base class implementation does nothing. Derived classes may override this to perform custom connection processing.

Parameters:
server - the host name
port - the port number
timeoutMS - the timeout value passed to the connect() call

preDisconnect

protected virtual void preDisconnect()
Protected function called when a socket connection is about to be closed from the client side. The base class implementation does nothing.



Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements