ionflux.org | Impressum

Ionflux::Tools::TCPSocket Class Reference
[Network interface]

TCP socket. More...

#include <TCPSocket.hpp>

Collaboration diagram for Ionflux::Tools::TCPSocket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TCPSocket ()
 Constructor.
 TCPSocket (int initPort)
 Constructor.
 TCPSocket (const std::string &initHost, int initPort)
 Constructor.
virtual ~TCPSocket ()
 Destructor.
virtual bool resolve ()
 Resolve remote hostname.
virtual bool connect ()
 Connect.
virtual void close ()
 Close connection.
virtual bool bind ()
 Bind socket.
virtual bool bind (unsigned int newAddress)
 Bind socket.
virtual bool listen ()
 Listen.
virtual int accept (sockaddr_in &newAddr, socklen_t &newAddrSize)
 Accept connection.
virtual bool accept (TCPSocket &newClientSocket)
 Accept connection.
virtual bool readBytes (std::string &bytes)
 Read bytes.
virtual bool sendBytes (const std::string &bytes)
 Send bytes.
virtual void setRemoteHost (const std::string &newHost)
 Set remote host.
virtual void setPort (int newPort)
 Set port.
virtual void setListenQueue (int newListenQueue)
 Set listen queue.
virtual void setFD (int newFD)
 Set file descriptor.
virtual void setConnectionState (bool newConnectionState)
 Set connection state.
virtual void setBindingState (bool newBindingState)
 Set binding state.
virtual void setListeningState (bool newListeningState)
 Set listening state.
virtual void setClientIP (const std::string &newClientIP)
 Set client IP.
virtual int getPort ()
 Get port.
virtual std::string getRemoteHost ()
 Get remote host.
virtual int getFD ()
 Get file descriptor.
virtual bool isConnected ()
 Connection state.
virtual int getListenQueue ()
 Get listen queue.
virtual bool isBound ()
 Binding state.
virtual bool isListening ()
 Listening state.
virtual std::string getClientIP ()
 Get client IP.
virtual ReportergetLog ()
 Get Console output/logging facility.

Static Public Attributes

static const int READ_BUFFER_SIZE = 1024
 Size of read buffer.
static const int DEFAULT_LISTEN_QUEUE = 10
 Default queue size for incoming connections.

Protected Attributes

Ionflux::Tools::Reporter log
 Console output/logging.
std::string remoteHostName
 Remote hostname.
std::string clientIP
 Client IP address.
int port
 Remote port number.
int theSocket
 Socket file descriptor.
bool connected
 Connection state.
bool bound
 Binding state.
bool listening
 Listening state.
sockaddr_in remoteHostAddress
 Address of the remote socket.
sockaddr_in localHostAddress
 Address of the local socket.
hostent * remoteHostEntry
 Host entry of the remote host.
int listenQueue
 Queue size for incoming connections.

Detailed Description

TCP socket.

Wrapper class for a TCP socket.


Constructor & Destructor Documentation

Ionflux::Tools::TCPSocket::TCPSocket  ) 
 

Constructor.

Construct a new TCPSocket object.

Ionflux::Tools::TCPSocket::TCPSocket int  initPort  ) 
 

Constructor.

Construct a new TCPSocket object.

Parameters:
initPort The port this socket object will connect to or listen on.

Ionflux::Tools::TCPSocket::TCPSocket const std::string &  initHost,
int  initPort
 

Constructor.

Construct a new TCPSocket object.

Parameters:
initHost The remote host this socket object will connect to.
initPort The port this socket object will connect to.

Ionflux::Tools::TCPSocket::~TCPSocket  )  [virtual]
 

Destructor.

Destruct TCPSocket object.


Member Function Documentation

bool Ionflux::Tools::TCPSocket::accept TCPSocket newClientSocket  )  [virtual]
 

Accept connection.

Accepts a new client connection on a listening socket and initializes a TCPSocket object appropriately. Returns true on success, false otherwise.

Note:
On success, you can use the new remote client socket for I/O like you would use a local client socket.
Parameters:
newClientSocket Where to store the new remote client socket.
Returns:
true on success, false otherwise.

int Ionflux::Tools::TCPSocket::accept sockaddr_in &  newAddr,
socklen_t &  newAddrSize
[virtual]
 

Accept connection.

Accepts a new client connection on a listening socket.

Note:
You must call listen() prior to accept().
Parameters:
newAddr Where to store the address of the connected peer.
newAddrSize Where to store size of the address of the connected peer.
Returns:
File descriptor of the new client socket.

bool Ionflux::Tools::TCPSocket::bind unsigned int  newAddress  )  [virtual]
 

Bind socket.

Bind a socket to a local port and interface. Pass INADDR_ANY to 'address' to bind to all available local interfaces. Returns true on success, false otherwise.

Parameters:
newAddress Local interface address to bind to.
Returns:
true on success, false otherwise.

bool Ionflux::Tools::TCPSocket::bind  )  [virtual]
 

Bind socket.

Bind a socket to a local port on all available local interfaces.

Returns:
true on success, false otherwise.

void Ionflux::Tools::TCPSocket::close  )  [virtual]
 

Close connection.

Closes the connection.

bool Ionflux::Tools::TCPSocket::connect  )  [virtual]
 

Connect.

Connect to remote host.

Returns:
true on success, false otherwise.

std::string Ionflux::Tools::TCPSocket::getClientIP  )  [virtual]
 

Get client IP.

Get the IP address which the socket is bound to.

Note:
For remote client sockets, the IP address will be set automatically by accept(). However, it will not be set automatically for a local client socket.
Returns:
IP address, in numbers-and-dots notation.

int Ionflux::Tools::TCPSocket::getFD  )  [virtual]
 

Get file descriptor.

Get the file descriptor associated with this socket object.

Returns:
Socket file descriptor..

int Ionflux::Tools::TCPSocket::getListenQueue  )  [virtual]
 

Get listen queue.

Get the listen queue size for a server socket.

Returns:
Listen queue size.

Reporter & Ionflux::Tools::TCPSocket::getLog  )  [virtual]
 

Get Console output/logging facility.

Returns:
The console output/logging facility used by this object.

int Ionflux::Tools::TCPSocket::getPort  )  [virtual]
 

Get port.

Get the port number this socket object will connect to.

Returns:
Port number.

string Ionflux::Tools::TCPSocket::getRemoteHost  )  [virtual]
 

Get remote host.

Get the hostname of the remote host this socket object will connect to.

Returns:
Hostname.

bool Ionflux::Tools::TCPSocket::isBound  )  [virtual]
 

Binding state.

Get the binding state of the socket.

Note:
This is only valid for server sockets.
Returns:
true if this socket object is bound to a local port, false otherwise.

bool Ionflux::Tools::TCPSocket::isConnected  )  [virtual]
 

Connection state.

Get the connection state.

Note:
This is only valid for client sockets.
Returns:
true if this socket object is connected, false otherwise.

bool Ionflux::Tools::TCPSocket::isListening  )  [virtual]
 

Listening state.

Get the listening state of the socket.

Note:
This is only valid for server sockets.
Returns:
true if this socket object is listening, false otherwise.

bool Ionflux::Tools::TCPSocket::listen  )  [virtual]
 

Listen.

Listen for incoming connections.

Note:
You must call bind() prior to listen().
Returns:
true on success, false otherwise.

bool Ionflux::Tools::TCPSocket::readBytes std::string &  bytes  )  [virtual]
 

Read bytes.

Read bytes from the socket.

Parameters:
bytes String to store incoming bytes.
Returns:
true on success, false otherwise.

bool Ionflux::Tools::TCPSocket::resolve  )  [virtual]
 

Resolve remote hostname.

Resolve the remote hostname.

Returns:
true on success, false otherwise.

bool Ionflux::Tools::TCPSocket::sendBytes const std::string &  bytes  )  [virtual]
 

Send bytes.

Send bytes over the socket.

Parameters:
bytes Bytes to send over the socket.
Returns:
true on success, false otherwise.

void Ionflux::Tools::TCPSocket::setBindingState bool  newBindingState  )  [virtual]
 

Set binding state.

Sets the binding state.

Note:
You should not normally use this, since the binding state is set automatically. However, if you want to construct a TCPSocket object for an existing file descriptor, it might be necessary to set the binding state manually.
Parameters:
newBindingState Binding state.

void Ionflux::Tools::TCPSocket::setClientIP const std::string &  newClientIP  )  [virtual]
 

Set client IP.

Sets the IP address of the client represented by this TCPSocket object.

Note:
This is used by accept() to store the IP address of a newly connected client. You should not normally set this by hand.
Parameters:
newClientIP Client IP.

void Ionflux::Tools::TCPSocket::setConnectionState bool  newConnectionState  )  [virtual]
 

Set connection state.

Sets the connection state.

Note:
You should not normally use this, since the connection state is set automatically. However, if you want to construct a TCPSocket object for an existing file descriptor, it might be necessary to set the connection state manually.
Parameters:
newConnectionState Connection state.

void Ionflux::Tools::TCPSocket::setFD int  newFD  )  [virtual]
 

Set file descriptor.

Sets the file descriptor associated with this socket object.

Note:
If the TCPSocket object is initialized and connected when you call this function, it will be closed and its internal state reset.
Parameters:
newFD Socket file descriptor.

void Ionflux::Tools::TCPSocket::setListeningState bool  newListeningState  )  [virtual]
 

Set listening state.

Sets the listening state.

Note:
You should not normally use this, since the listening state is set automatically. However, if you want to construct a TCPSocket object for an existing file descriptor, it might be necessary to set the listening state manually.
Parameters:
newListeningState Listening state.

void Ionflux::Tools::TCPSocket::setListenQueue int  newListenQueue  )  [virtual]
 

Set listen queue.

Sets the size of the queue for incoming connections.

Note:
This is only valid for server sockets.
Parameters:
newListenQueue Queue size for incoming connections.

void Ionflux::Tools::TCPSocket::setPort int  newPort  )  [virtual]
 

Set port.

Sets the port this socket object will connect to.

Parameters:
newPort Port number of the remote host.

void Ionflux::Tools::TCPSocket::setRemoteHost const std::string &  newHost  )  [virtual]
 

Set remote host.

Sets the remote host this socket object will connect to. You can specify either a host name or an IP address.

Parameters:
newHost Hostname of the remote host.


Member Data Documentation

bool Ionflux::Tools::TCPSocket::bound [protected]
 

Binding state.

std::string Ionflux::Tools::TCPSocket::clientIP [protected]
 

Client IP address.

This is used by accept() to store the IP address of a connected client.

bool Ionflux::Tools::TCPSocket::connected [protected]
 

Connection state.

const int Ionflux::Tools::TCPSocket::DEFAULT_LISTEN_QUEUE = 10 [static]
 

Default queue size for incoming connections.

bool Ionflux::Tools::TCPSocket::listening [protected]
 

Listening state.

int Ionflux::Tools::TCPSocket::listenQueue [protected]
 

Queue size for incoming connections.

struct sockaddr_in Ionflux::Tools::TCPSocket::localHostAddress [protected]
 

Address of the local socket.

Ionflux::Tools::Reporter Ionflux::Tools::TCPSocket::log [protected]
 

Console output/logging.

int Ionflux::Tools::TCPSocket::port [protected]
 

Remote port number.

const int Ionflux::Tools::TCPSocket::READ_BUFFER_SIZE = 1024 [static]
 

Size of read buffer.

struct sockaddr_in Ionflux::Tools::TCPSocket::remoteHostAddress [protected]
 

Address of the remote socket.

struct hostent* Ionflux::Tools::TCPSocket::remoteHostEntry [protected]
 

Host entry of the remote host.

std::string Ionflux::Tools::TCPSocket::remoteHostName [protected]
 

Remote hostname.

int Ionflux::Tools::TCPSocket::theSocket [protected]
 

Socket file descriptor.


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:11:09 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6