TCP client to connect to a TcpListener.
More...
#include <tcp_client.h>
|
| TcpClient (std::string ipAddress, uint16_t port) |
| Constructor. More...
|
|
int | Connection () const noexcept override |
| Connection descriptor for sending and receiving. More...
|
|
bool | IsConnected () const noexcept |
| Inidicates whether the client is connected or not. More...
|
|
bool | TrySetup () noexcept override |
| Try to setup the communicator. More...
|
|
bool | TryConnect () noexcept |
| Try to connect to the server. More...
|
|
template<std::size_t N> |
ssize_t | Send (const std::array< uint8_t, N > &buffer) const noexcept |
| Send a byte array to the connected client. More...
|
|
template<std::size_t N> |
ssize_t | Receive (std::array< uint8_t, N > &buffer) const noexcept |
| Receive a byte array from the connected client. More...
|
|
int | Descriptor () const noexcept |
| File descriptor. More...
|
|
virtual bool | TryClose () noexcept |
| Try to close the communicator. More...
|
|
|
| NetworkSocket (std::string ipAddress, uint16_t port) |
| Constructor. More...
|
|
const std::string | IpAddress |
| Listening/Connecting IP address for server/client.
|
|
const uint16_t | Port |
| Listening/Connecting port number for server/client.
|
|
int | FileDescriptor |
| File descriptor.
|
|
TCP client to connect to a TcpListener.
- See also
- TcpListener
◆ TcpClient()
AsyncBsdSocketLib::TcpClient::TcpClient |
( |
std::string |
ipAddress, |
|
|
uint16_t |
port |
|
) |
| |
Constructor.
- Parameters
-
ipAddress | Server IP address |
port | Server port number |
◆ Connection()
int AsyncBsdSocketLib::TcpClient::Connection |
( |
| ) |
const |
|
overridevirtualnoexcept |
Connection descriptor for sending and receiving.
- Returns
- A non-negative value if there is a valid connection; otherwise -1
Implements AsyncBsdSocketLib::Communicator.
◆ IsConnected()
bool AsyncBsdSocketLib::TcpClient::IsConnected |
( |
| ) |
const |
|
noexcept |
Inidicates whether the client is connected or not.
- Returns
- True if the client is connected; otherwise false
◆ Receive()
template<std::size_t N>
ssize_t AsyncBsdSocketLib::TcpClient::Receive |
( |
std::array< uint8_t, N > & |
buffer | ) |
const |
|
inlinenoexcept |
Receive a byte array from the connected client.
- Template Parameters
-
- Parameters
-
buffer | Receive buffer byte array |
- Returns
- Size of received bytes (-1 in case of receiving failed)
- Warning
- Due to edge-triggered polling, starvation can occur
◆ Send()
template<std::size_t N>
ssize_t AsyncBsdSocketLib::TcpClient::Send |
( |
const std::array< uint8_t, N > & |
buffer | ) |
const |
|
inlinenoexcept |
Send a byte array to the connected client.
- Template Parameters
-
- Parameters
-
buffer | Send buffer byte array |
- Returns
- Size of sent bytes (-1 in case of sending failed)
◆ TryConnect()
bool AsyncBsdSocketLib::TcpClient::TryConnect |
( |
| ) |
|
|
noexcept |
Try to connect to the server.
- Returns
- True if the client is successfully connected; otherwise false
◆ TrySetup()
bool AsyncBsdSocketLib::TcpClient::TrySetup |
( |
| ) |
|
|
overridevirtualnoexcept |