A class representing a TCP socket.
More...
#include <tcp_socket.hpp>
A class representing a TCP socket.
This class is used to create and manage TCP sockets. A TCPSocket object can only be moved, not copied.
◆ TCPSocket() [1/3]
◆ ~TCPSocket()
TCPSocket::~TCPSocket |
( |
| ) |
|
◆ TCPSocket() [2/3]
◆ TCPSocket() [3/3]
◆ accept()
std::unique_ptr< TCPSocket > TCPSocket::accept |
( |
| ) |
|
Accept incoming connection.
- Returns
- A new TCPSocket object representing the connection
◆ bind()
bool TCPSocket::bind |
( |
const std::string & | ip, |
|
|
uint16_t | port ) |
Bind the socket to a port.
- Parameters
-
ip | The IP address to bind to, or an empty string to bind to all interfaces |
port | The port to bind to |
- Returns
- true on success, false on failure
◆ connect()
bool TCPSocket::connect |
( |
const std::string & | ip, |
|
|
uint16_t | port ) |
Connect to a server at a given ip and port.
- Returns
- true on success, false on failure
◆ disconnect()
bool TCPSocket::disconnect |
( |
| ) |
|
Disconnect from whatever the socket is connected to.
- Returns
- true on success, false on failure
◆ get_local_ip()
std::string TCPSocket::get_local_ip |
( |
| ) |
const |
Get the IP address of the local socket.
- Returns
- The IP address of the local socket
◆ get_local_port()
uint16_t TCPSocket::get_local_port |
( |
| ) |
const |
Get the port of the local socket.
- Returns
- The port of the local socket
◆ get_peer_ip()
std::string TCPSocket::get_peer_ip |
( |
| ) |
const |
Get the IP address of the connected peer.
- Returns
- The IP address of the connected peer
◆ get_peer_port()
uint16_t TCPSocket::get_peer_port |
( |
| ) |
const |
Get the port of the connected peer.
- Returns
- The port of the connected peer
◆ listen()
bool TCPSocket::listen |
( |
int | listen_backlog | ) |
|
Listen for incoming connections.
- Parameters
-
listen_backlog | The maximum number of pending connections |
- Returns
- true on success, false on failure
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ receive_data()
std::string TCPSocket::receive_data |
( |
bool | peek = false | ) |
|
Receive data from the socket.
- Returns
- The received data
◆ send_data()
ssize_t TCPSocket::send_data |
( |
const std::string & | data | ) |
|
Send data over the socket.
- Returns
- The number of bytes sent
◆ set_non_blocking()
bool TCPSocket::set_non_blocking |
( |
bool | non_blocking | ) |
|
Set the socket non-blocking mode.
- Returns
- true on success, false on failure
◆ operator==
◆ TCPServer
The documentation for this class was generated from the following files: