Use a SocketDescriptor as a client (example a TCP or UDP socket client). More...
#include <Socket.h>
Public Member Functions | |
| SocketClient (const SocketDescriptor &socket) | |
| Constructs this SocketClient from a SocketDescriptor (already created with SocketDescriptor::create) | |
| Result | connect (StringSpan address, uint16_t port) |
| Connect to a given address and port combination. | |
| Result | connect (SocketIPAddress ipAddress) |
| Connect to a given address and port combination. | |
| Result | write (Span< const char > data) |
| Writes bytes to this socket. | |
| Result | read (Span< char > data, Span< char > &readData) |
| Read bytes from this socket blocking until they're actually received. | |
| Result | readWithTimeout (Span< char > data, Span< char > &readData, int64_t timeout) |
| Read bytes from this socket blocking until they're actually received or timeout occurs. | |
Use a SocketDescriptor as a client (example a TCP or UDP socket client).
The socket client can be obtained via SC::SocketServer::accept or connected to an endpoint through SC::SocketClient::connect.
Example (accepted client from server, doing a synchronous read):
Example (connecting client to server, doing two synchronous writes):
|
inline |
Constructs this SocketClient from a SocketDescriptor (already created with SocketDescriptor::create)
| socket | A socket descriptor created with SocketDescriptor::create to be used as client |
| Result SC::SocketClient::connect | ( | SocketIPAddress | ipAddress | ) |
Connect to a given address and port combination.
| ipAddress | Address and port to connect to |
| Result SC::SocketClient::connect | ( | StringSpan | address, |
| uint16_t | port ) |
Connect to a given address and port combination.
| address | Address as ASCII encoded string |
| port | Port to start listening to |
| Result SC::SocketClient::readWithTimeout | ( | Span< char > | data, |
| Span< char > & | readData, | ||
| int64_t | timeout ) |
Read bytes from this socket blocking until they're actually received or timeout occurs.
| [in] | data | Span of memory pointing at a buffer that will receive the read data |
| [out] | readData | A sub-Span of data that has the length of actually read bytes |
| [in] | timeout | For how many milliseconds the read should wait before timing out |
Writes bytes to this socket.
| data | Bytes to write to this socket |