Socket class.
More...
#include <Socket.h>
List of all members.
Public Member Functions |
PLCORE_API | Socket () |
| Constructor.
|
| Socket (const Socket &cSocket) |
| Copy constructor.
|
| Socket (handle nSocket) |
| Constructor.
|
| ~Socket () |
| Destructor.
|
PLCORE_API bool | IsValid () const |
| Returns whether the socket is currently valid.
|
PLCORE_API bool | Close () |
| Closes the socket.
|
const SocketAddress & | GetSocketAddress () const |
| Returns the socket address object.
|
bool | Connect (const String &sAddress, uint32 nPort) |
| Establishes a connection to a host by using an address and port.
|
PLCORE_API bool | Connect (const SocketAddress &cSocketAddress) |
| Establishes a connection to a host by using a given socked address.
|
bool | Bind (uint32 nPort) |
| Associate local address with socket.
|
bool | Bind (const String &sAddress, uint32 nPort) |
| Associate local address with socket.
|
PLCORE_API bool | Bind (const SocketAddress &cSocketAddress) |
| Associate local address with socket.
|
PLCORE_API bool | Listen (int nMaxQueue=0) const |
| Mark a socket as accepting connections.
|
PLCORE_API Socket | Accept () const |
| Accept a connection on a socket (blocking)
|
PLCORE_API int | Send (const char *pBuffer, uint32 nSize) const |
| Sends data.
|
PLCORE_API bool | IsDataWaiting () const |
| Returns whether or not data is waiting to be received (non-blocking request)
|
PLCORE_API int | Receive (char *pBuffer, uint32 nSize) const |
| Receives data (blocking request)
|
Detailed Description
Constructor & Destructor Documentation
Copy constructor.
- Parameters:
-
[in] | cSocket | Socket to copy from |
Constructor.
- Parameters:
-
[in] | nSocket | System socket handle |
- Note:
- Should be used mainly to create an invalid socket ('INVALID_SOCKET')
Member Function Documentation
Returns whether the socket is currently valid.
- Returns:
- 'true' if the socket is currently valid, else 'false'
Closes the socket.
- Returns:
- 'true' if all went fine, else 'false' (maybe it's already closed?)
Returns the socket address object.
- Returns:
- The socket address object
Establishes a connection to a host by using an address and port.
- Parameters:
-
[in] | sAddress | Address of the host to connect to |
[in] | nPort | Number of the port to use |
- Returns:
- 'true' if all went fine, else 'false'
Establishes a connection to a host by using a given socked address.
- Parameters:
-
[in] | cSocketAddress | Socket address of the host to connect to |
- Returns:
- 'true' if all went fine, else 'false'
Associate local address with socket.
- Parameters:
-
[in] | nPort | Number of the port to use |
- Returns:
- 'true' if all went fine, else 'false'
Associate local address with socket.
- Parameters:
-
[in] | sAddress | Address of the host to bind to |
[in] | nPort | Number of the port to use |
- Returns:
- 'true' if all went fine, else 'false'
Associate local address with socket.
- Parameters:
-
[in] | cSocketAddress | Socket address of the host to bind to |
- Returns:
- 'true' if all went fine, else 'false'
Mark a socket as accepting connections.
- Parameters:
-
[in] | nMaxQueue | Maximum length of the queue of pending connections |
- Returns:
- 'true' if all went fine, else 'false'
Accept a connection on a socket (blocking)
- Returns:
- Socket with the accepted connection or an invalid socket on error
Sends data.
- Parameters:
-
[in] | pBuffer | Data to send, if a null pointer, nothing is send |
[in] | nSize | Size in bytes of the buffer to send, MUST be valid! |
- Returns:
- Total number of bytes sent which can be less than the number requested to be sent, negative value on error
Returns whether or not data is waiting to be received (non-blocking request)
- Returns:
- 'true' if data is waiting to be received, else 'false'
Receives data (blocking request)
- Parameters:
-
[out] | pBuffer | Buffer that receives the data, if a null pointer, nothing can be received |
[in] | nSize | Size in bytes of the buffer that receives the data, MUST be valid! |
- Returns:
- Total number of received bytes, negative value on error
- Note:
- If there is currently not enough data available, this function will read as much as possible, meaning that less data can be read than requested
- If more data is waiting to be received as the given buffer is able to store, you have to call this method multiple times in order to gather all waiting data
The documentation for this class was generated from the following files: