Use a SocketDescriptor as a client (example a TCP or UDP socket client). More...
#include <SocketDescriptor.h>
Public Member Functions | |
SocketClient (const SocketDescriptor &socket) | |
Constructs this SocketClient from a SocketDescriptor (already created with SocketDescriptor::create) More... | |
Result | connect (StringView address, uint16_t port) |
Connect to a given address and port combination. More... | |
Result | connect (SocketIPAddress ipAddress) |
Connect to a given address and port combination. More... | |
Result | write (Span< const char > data) |
Writes bytes to this socket. More... | |
Result | read (Span< char > data, Span< char > &readData) |
Read bytes from this socket blocking until they're actually received. More... | |
Result | readWithTimeout (Span< char > data, Span< char > &readData, Time::Milliseconds timeout) |
Read bytes from this socket blocking until they're actually received or timeout occurs. More... | |
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 | ( | StringView | address, |
uint16_t | port | ||
) |
Connect to a given address and port combination.
address | Address as string |
port | Port to start listening to |
Result SC::SocketClient::readWithTimeout | ( | Span< char > | data, |
Span< char > & | readData, | ||
Time::Milliseconds | 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 |