Google

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

TCPSocket Class Reference

TCP sockets are used for stream based connected sessions between two sockets. bound server for TCP streams and sessions. More...

#include <socket.h>

Inheritance diagram for TCPSocket:

Socket List of all members.

Public Methods

 TCPSocket (const InetAddress &bind, tpport_t port, int backlog = 5)
 A TCP "server" is created as a TCP socket that is bound to a hardware address and port number on the local machine and that has a backlog queue to listen for remote connection requests. More...

InetHostAddress getRequest (tpport_t *port = NULL) const
 Return address and port of next connection request. More...

void Reject (void)
 Used to reject the next incoming connection request.

InetHostAddress getLocal (tpport_t *port = NULL) const
 Used to get local bound address.

bool isPendingConnection (timeout_t timeout = TIMEOUT_INF)
 not const -- jfc.

 ~TCPSocket ()
 Use base socket handler for ending this socket.


Protected Methods

virtual bool OnAccept (const InetHostAddress &ia, short port)
 DO NOT OVERWRITE THIS method anymore. More...

virtual bool OnAccept (const InetHostAddress &ia, tpport_t port)
 A method to call in a derived TCPSocket class that is acting as a server when a connection request is being accepted. More...


Friends

class  TCPStream
class  SocketPort
class  tcpstream

Detailed Description

TCP sockets are used for stream based connected sessions between two sockets. bound server for TCP streams and sessions.

Both error recovery and flow control operate transparently for a TCP socket connection. The TCP socket base class is primary used to bind a TCP "server" for accepting TCP streams.

An implicit and unique TCPSocket object exists in Common C++ to represent a bound TCP socket acting as a "server" for receiving connection requests. This class is not part of TCPStream because such objects normally perform no physical I/O (read or write operations) other than to specify a listen backlog queue and perform "accept" operations for pending connections. The Common C++ TCPSocket offers a Peek method to examine where the next pending connection is coming from, and a Reject method to flush the next request from the queue without having to create a session.

The TCPSocket also supports a "OnAccept" method which can be called when a TCPStream related object is created from a TCPSocket. By creating a TCPStream from a TCPSocket, an accept operation automatically occurs, and the TCPSocket can then still reject the client connection through the return status of it's OnAccept method.

Author(s):
David Sugar <dyfet@tycho.com>


Constructor & Destructor Documentation

TCPSocket::TCPSocket ( const InetAddress & bind,
tpport_t port,
int backlog = 5 )
 

A TCP "server" is created as a TCP socket that is bound to a hardware address and port number on the local machine and that has a backlog queue to listen for remote connection requests.

If the server cannot be created, an exception is thrown.

Parameters:
bind   local ip address or interface to use.
port   number to bind socket under.
backlog   size of connection request queue.

TCPSocket::~TCPSocket ( ) [inline]
 

Use base socket handler for ending this socket.


Member Function Documentation

bool TCPSocket::OnAccept ( const InetHostAddress & ia,
tpport_t port ) [inline, protected, virtual]
 

A method to call in a derived TCPSocket class that is acting as a server when a connection request is being accepted.

The server can implement protocol specific rules to exclude the remote socket from being accepted by returning false. The Peek method can also be used for this purpose.

Returns:
true if client should be accepted.
Parameters:
ia   internet host address of the client.
port   number of the client.

bool TCPSocket::OnAccept ( const InetHostAddress & ia,
short port ) [inline, protected, virtual]
 

DO NOT OVERWRITE THIS method anymore.

THIS WILL NOT WORK! use bool OnAccept(const InetHostAddress &ia, tpport_t port) instead.

Deprecated:

void TCPSocket::Reject ( void )
 

Used to reject the next incoming connection request.

InetHostAddress TCPSocket::getLocal ( tpport_t * port = NULL ) const [inline]
 

Used to get local bound address.

Reimplemented from Socket.

InetHostAddress TCPSocket::getRequest ( tpport_t * port = NULL ) const [inline]
 

Return address and port of next connection request.

This can be used instead of OnAccept() to pre-evaluate connection requests.

Returns:
host requesting a connection.
Parameters:
port   number of requestor.

bool TCPSocket::isPendingConnection ( timeout_t timeout = TIMEOUT_INF ) [inline]
 

not const -- jfc.


Friends And Related Function Documentation

class SocketPort [friend]
 

class TCPStream [friend]
 

class tcpstream [friend]
 


The documentation for this class was generated from the following file:
Generated at Fri Mar 23 10:47:56 2001 for CommonC++ by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000