TCP socket class. More...
#include <TcpSocket.h>
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 |
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.
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.
bool TcpSocket::close | ( | ) |
Close socket.
Closes the socket.
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.
host | Contains the remote host name or IP address in text format. | |
port | Specifies the remote port number. |
size_t TcpSocket::getPendingInput | ( | ) |
Get pending input length.
size_t TcpSocket::getPendingOutput | ( | ) |
Get pending output length.
bool TcpSocket::isConnected | ( | ) |
Check connection state.
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.
pData | Points to the buffer that receives incoming data. | |
maxLen | Specifies the maximum length of data to receive. |
bool TcpSocket::setKeepalive | ( | int | keepIdle, | |
int | keepInterval, | |||
int | keepCount | |||
) |
Set socket keepalive.
Sets new socket keepalive 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. |
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.
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.
pData | Points to the data buffer about to be sent. | |
dataLen | Specifies the length of the data in bytes. |
int TcpSocket::recvTimeout [protected] |
Receive timeout setting
int TcpSocket::sendTimeout [protected] |
Send timeout setting
int TcpSocket::socketHandle [protected] |
Handle to the TCP socket opened