|
My Project
|
This class implements all methods shared by TCP and UDP sockets.
#include <CSocket.h>

Public Member Functions | |
| cSocket () | |
| cSocket (int a_socket) | |
| virtual | ~cSocket () |
| int | getLocalPort () |
| This method returns the local port number that the socket is connected to. | |
| std::string | getRemoteIP () |
| This method retrieves the remote IP address that the socket is connected to. | |
| int | getRemotePort () |
| This method returns the remote port number that the socket is connected to. | |
| int | close () |
| This method closes the socket. | |
| int | peek (char *a_output, unsigned int a_size) |
| This method reads a copy of incoming data (without removing the data). | |
| int | peek (std::string &a_output) |
| This method reads a copy of incoming data (without removing the data). | |
| int | read (char *a_output, unsigned int a_size) |
| This method reads a incoming data. | |
| int | read (std::string &a_output) |
| This method reads a incoming data. | |
| int | readLine (char *a_output, unsigned int a_size) |
| This method reads an entire line of data (delimited by the '\n' character). | |
| int | readLine (std::string &a_output) |
| This method reads an entire line of data (delimited by the '\n' character). | |
| int | send (const char *a_data, int a_length) |
| This method sends data through the socket. | |
| int | send (std::string a_data) |
| This method sends data through the socket. | |
| double | getTimeout () |
| This method retrieves the socket timeout in (s). | |
| int | setTimeout (double a_timeout) |
| This method sets the socket timeout in (s). | |
| int | getSendSize () |
| This method retrieves the socket outgoing buffer size. | |
| int | setSendSize (int a_size) |
| This method sets the socket outgoing buffer size. | |
| int | getRecvSize () |
| This method retrieves the socket incoming buffer size. | |
| int | setRecvSize (int a_size) |
| This method sets the socket incoming buffer size. | |
| virtual unsigned char | getAttributes ()=0 |
| This method retrieves the socket attributes. | |
| virtual int | setAttributes (unsigned char a_attributes)=0 |
| This method sets the socket attributes. | |
Static Public Member Functions | |
| static std::string | getLocalIP () |
| This method retrieves the local IP address. | |
Static Public Attributes | |
| static const unsigned int | BUFFERSIZE = 2048 |
| This constant defines the default outgoing and incoming socket buffer sizes. | |
| static const unsigned char | BLOCKING = 0x01 |
| This constant defines the attribute bit to hold the socket BLOCKING attribute. | |
| static const unsigned char | REUSEADDR = 0x02 |
| This constant defines the attribute bit to hold the socket REUSEADDR attribute. | |
| static const unsigned char | NODELAY = 0x04 |
| This constant defines the attribute bit to hold the socket NODELAY attribute. | |
| static const unsigned char | DEFAULT_ATTR = 0x00 | BLOCKING | REUSEADDR | ~NODELAY |
| This constant defines the default attributes for new sockets. | |
| static const int | WOULDBLOCK = -2 |
| This return constant is used to signify that a non-blocking socket would block. | |
| static const int | SHORTLINE = -3 |
| This return constant is used to signify that a buffer is too small to hold a line. | |
| static const int | TIMEOUT = -4 |
| This return constant is used to signify that a read operation on a socket has timed out. | |
Protected Member Functions | |
| unsigned char | getBaseAttributes () |
| This method retrieves the socket attributes shared between TCP and UDP. | |
| int | setBaseAttributes (unsigned char a_attributes) |
| This method sets the socket attributes shared between TCP and UDP. | |
Protected Attributes | |
| int | m_socket |
| Unique socket identifier. | |
| unsigned char | m_attributes |
| Socket attributes. | |
| char | m_buffer [BUFFERSIZE] |
| Socket read buffer. | |
| unsigned long | m_remoteIP |
| Socket remote IP address. | |
| unsigned int | m_remotePort |
| Socket remote port number. | |
| unsigned long | m_localIP |
| Socket local IP address. | |
| unsigned int | m_localPort |
| Socket local port number. | |
| chai3d::cSocket::cSocket | ( | ) |
Constructor of cSocket.
This method calls the global initialization function and sets sensible initial values for all data members.
| chai3d::cSocket::cSocket | ( | int | a_socket | ) |
Constructor of cSocket.
This method creates a base socket object around an existing socket handle and sets sensible initial values for all other data members.
| a_socket | A valid handle to an existing socket. |
|
virtual |
Destructor of cSocket.
|
static |
This method retrieves the local IP address. If the system is connected to the network, this method returns the first non-loopback IP address available on the system. Otherwise, the loopback adapter address (usually 127.0.0.1) is returned.
| int chai3d::cSocket::getLocalPort | ( | ) |
This method retrieves the local port number that the socket is connected to. If the socket is not connected, 0 is returned.
| std::string chai3d::cSocket::getRemoteIP | ( | ) |
This method retrieves the remote IP address. If the socket is connected to a remote system, this method returns the remote IP address. Otherwise, an illegal IP address is returned (0.0.0.0).
| int chai3d::cSocket::getRemotePort | ( | ) |
This method retrieves the remote port number that the socket is connected to. If the socket is not connected, 0 is returned.
| int chai3d::cSocket::close | ( | ) |
This method closes the socket.
| int chai3d::cSocket::peek | ( | char * | a_output, |
| unsigned int | a_size | ||
| ) |
This method reads any available data on a socket into a given buffer, but without emptying the buffer. The size of the buffer returned depends on the buffer size and the amount of available data (whichever is smaller). If the BLOCKING attribute is set, the call blocks until data is available. Otherwise, the call returns immediately if no data is available.
| a_output | A buffer to collect the data requested. |
| a_size | The size of the a_output buffer in bytes. |
| int chai3d::cSocket::peek | ( | std::string & | a_output | ) |
This method reads any available data on a socket into a given string, but without emptying the buffer. The size of the string returned depends on the the amount of available data. If the BLOCKING attribute is set, the call blocks until data is available. Otherwise, the call returns immediately if no data is available.
| a_output | A string to collect the data requested. |
| int chai3d::cSocket::read | ( | char * | a_output, |
| unsigned int | a_size | ||
| ) |
This method reads any available data on a socket into a given buffer. The size of the buffer returned depends on the buffer size and the amount of available data (whichever is smaller). If the BLOCKING attribute is set, the call blocks until data is available. Otherwise, the call returns immediately if no data is available.
| a_output | A buffer to collect the data requested. |
| a_size | The size of the a_output buffer in bytes. |
| int chai3d::cSocket::read | ( | std::string & | a_output | ) |
This method reads any available data on a socket into a given string. The size of the buffer returned depends on the amount of available data. If the BLOCKING attribute is set, the call blocks until data is available. Otherwise, the call returns immediately if no data is available.
| a_output | A string to collect the data requested. |
| int chai3d::cSocket::readLine | ( | char * | a_output, |
| unsigned int | a_size | ||
| ) |
This method reads a '
' terminated line of data on a socket into a given buffer. The size of the buffer returned depends on the buffer size and the amount of available data (whichever is smaller). If the BLOCKING attribute is set, the call blocks until data is available. Otherwise, the call returns immediately if no data is available. If the buffer is too small to hold a line, cSocket::SHORTLINE is returned.
| a_output | A buffer to collect the data requested. |
| a_size | The size of the a_output buffer in bytes. |
| int chai3d::cSocket::readLine | ( | std::string & | a_output | ) |
This method reads a '
' terminated line of data on a socket into a given string. The size of the buffer returned depends on the amount of available data. If the BLOCKING attribute is set, the call blocks until data is available. Otherwise, the call returns immediately if no data is available.
| a_output | A string to collect the data requested. |
| int chai3d::cSocket::send | ( | const char * | a_data, |
| int | a_length | ||
| ) |
This method sends data over a socket.
| a_data | A buffer containing the data to send. |
| a_length | The data buffer length in bytes. |
| int chai3d::cSocket::send | ( | std::string | a_data | ) |
This method sends data over the socket.
| a_data | A string containing the data to send. |
| double chai3d::cSocket::getTimeout | ( | ) |
This method sets the timeout value in seconds for the socket.
| int chai3d::cSocket::setTimeout | ( | double | a_timeout | ) |
This method retrieves the timeout value in seconds for a given socket.
| a_timeout | The timeout value in seconds. |
| int chai3d::cSocket::getSendSize | ( | ) |
This method retrieves the socket outgoing buffer size.
| int chai3d::cSocket::setSendSize | ( | int | a_size | ) |
This method sets the socket outgoing buffer size.
| a_size | Outgoing buffer size in bytes. |
| int chai3d::cSocket::getRecvSize | ( | ) |
This method retrieves the socket incoming buffer size.
| int chai3d::cSocket::setRecvSize | ( | int | a_size | ) |
This method sets the socket incoming buffer size.
| a_size | Incoming buffer size in bytes. |
|
pure virtual |
Implemented in chai3d::cSocketUDP, and chai3d::cSocketTCP.
|
pure virtual |
Implemented in chai3d::cSocketUDP, and chai3d::cSocketTCP.
|
protected |
This method retrieves the socket attributes that are shared between TCP and UDP configurations.
Attributes are single bit flags contained in a single byte. The following attributes are available:
|
protected |
This method sets the socket attributes that are shared between TCP and UDP configurations.
This includes the following attributes:
| a_attributes | A bitwise mask describing the socket attributes. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |