TcpSocket Class Reference

TCP socket class. More...

#include <TcpSocket.h>

List of all members.

Public Member Functions

 TcpSocket ()
 Class constructor.
virtual ~TcpSocket ()
 Class destructor.
bool connect (const char *host, int port)
 Connect socket.
bool close ()
 Close socket.
bool isConnected ()
 Check connection state.
bool writeData (unsigned char *pData, size_t dataLen)
 Write socket data.
size_t readData (unsigned char *pData, size_t maxLen)
 Read socket data.
size_t getPendingInput ()
 Get pending input length.
size_t getPendingOutput ()
 Get pending output length.
bool setTimeouts (int sendTout, int recvTout)
 Set socket timeouts.
bool setKeepalive (int keepIdle, int keepInterval, int keepCount)
 Set socket keepalive.

Protected Attributes

int socketHandle
int recvTimeout
int sendTimeout

Detailed Description

TCP socket class.

Provides a wrapper class implementation for the BSD compatible socket I/O. Socket class is designed to simplify the handling of a blocking client socket in the user application.


Constructor & Destructor Documentation

TcpSocket::TcpSocket (  ) 

Class constructor.

Initializes the socket object. Socket timeouts are set to default values of 30 seconds.

TcpSocket::~TcpSocket (  )  [virtual]

Class destructor.

Destroys the socket object.


Member Function Documentation

bool TcpSocket::close (  ) 

Close socket.

Closes the socket.

Returns:
Returns true if the operation was a success.
bool TcpSocket::connect ( const char *  host,
int  port 
)

Connect socket.

Creates a socket and connects to the specified host, given the host name or IP address and the port number.

Parameters:
host Contains the remote host name or IP address in text format.
port Specifies the remote port number.
Returns:
Returns true if the socket was successfully connected.
size_t TcpSocket::getPendingInput (  ) 

Get pending input length.

Returns:
Returns the number of unread bytes pending in the socket receive buffer.
size_t TcpSocket::getPendingOutput (  ) 

Get pending output length.

Returns:
Returns the number of unsent bytes pending in the socket transmit buffer.
bool TcpSocket::isConnected (  ) 

Check connection state.

Returns:
Returns true if the socket is connected to a remote host.
size_t TcpSocket::readData ( unsigned char *  pData,
size_t  maxLen 
)

Read socket data.

Receives data from the socket originating from a remote host. The function blocks until a portion of data has been received, or the socket receive timeout expires. Receive may return less data than specified by maxLen depending on the underlying protocols.

Parameters:
pData Points to the buffer that receives incoming data.
maxLen Specifies the maximum length of data to receive.
Returns:
Returns the number of bytes received from the socket.
bool TcpSocket::setKeepalive ( int  keepIdle,
int  keepInterval,
int  keepCount 
)

Set socket keepalive.

Sets new socket keepalive parameters.

Parameters:
keepIdle Specifies the time period after which the first keepalive is sent, in seconds.
keepInterval Specifies the time interval between consequent keepalives, in seconds.
keepCount Specifies the maximum number of keepalive probes sent before the connection is dropped.
Returns:
Returns true if the keepalive settings have been set successfully.
bool TcpSocket::setTimeouts ( int  sendTout,
int  recvTout 
)

Set socket timeouts.

Sets new socket timeout values. The timeouts are effective immediately if the socket is already connected, or cached until a new connection is made.

Parameters:
sendTout Specifies the socket send timeout, in milliseconds.
recvTout Specifies the socket receive and connect timeout, in milliseconds.
bool TcpSocket::writeData ( unsigned char *  pData,
size_t  dataLen 
)

Write socket data.

Writes data to the socket and sends data to remote host.

Parameters:
pData Points to the data buffer about to be sent.
dataLen Specifies the length of the data in bytes.
Returns:
Returns true if all data bytes were sent successfully.

Member Data Documentation

int TcpSocket::recvTimeout [protected]

Receive timeout setting

int TcpSocket::sendTimeout [protected]

Send timeout setting

int TcpSocket::socketHandle [protected]

Handle to the TCP socket opened


The documentation for this class was generated from the following files:
Generated on Wed Oct 20 11:13:45 2010 for libspatha by  doxygen 1.6.3