|
|
int | m_fd = -1 |
|
bool | m_closed = true |
|
std::shared_ptr< spdlog::logger > | m_log |
◆ close_socket()
| void Socket::close_socket |
( |
| ) |
|
closes the socket locally
◆ init_client()
| void Socket::init_client |
( |
const std::string & | ip_address, |
|
|
uint16_t | port ) |
Opens an IPv4 TCP Socket, and connects to a remote socket via ip address and port number
- Parameters
-
| ip_address | of remote socket |
| port | of remote socket |
◆ init_server()
| void Socket::init_server |
( |
uint16_t | port | ) |
|
Opens an IPv4 TCP Socket, binds it to a specified port and makes it listen to every host
- Parameters
-
◆ init_socket()
| void Socket::init_socket |
( |
uint16_t | port | ) |
|
◆ recv_all()
| void Socket::recv_all |
( |
void * | buf, |
|
|
size_t | len ) |
gets data from a remote socket and keeps reading in until the buffer is full
- Parameters
-
| buf | buffer that bytes get loaded into |
| len | length of the buffer |
◆ recv_json()
| std::optional< json > Socket::recv_json |
( |
| ) |
|
|
nodiscard |
Receives JSON data from the remote client.
- Reads in 4 byte determining the size of the JSON data
- Prepares a buffer and reads in size bytes into the buffer (reads in the JSON data)
- Returns
- the received JSON data or a nullptr if nothing was sent
◆ send_all()
| void Socket::send_all |
( |
const void * | buf, |
|
|
size_t | len ) const |
sends data to a remote socket and keeps sending bytes until all bytes are sent
- Parameters
-
| buf | buffer that bytes get loaded from |
| len | length of the buffer |
◆ send_json()
| void Socket::send_json |
( |
const json & | data | ) |
const |
Sends JSON data to the remote client by following protocol orders
- send 4 byte containing the size of the JSON data, so the receiver can prepare a big enough buffer
- send the JSON data
- Parameters
-
| data | to be sent over the socket |
◆ shutdown_socket()
| void Socket::shutdown_socket |
( |
| ) |
|
Shuts the connection down effectively letting the other client know that the connection should be closed now.
The documentation for this class was generated from the following file: